【发布时间】:2020-06-23 16:31:32
【问题描述】:
是否可以通过 Kestrel 的“代码”设置“aspNetCore requestTimeout”值(参见下面的 xml).........?
我在 KestrelServerLimits 对象上找不到任何东西。
以下是 xml 代码.......但希望在 CODE 中执行此操作,而不是通过(已发布)xml。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore requestTimeout="00:20:00" processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
我尝试了以下(“ serverOptions.Limits.KeepAliveTimeout = TimeSpan.FromSeconds(5); ”)......但这确实不控制我的邮递员测试中的服务器超时。
namespace MyStuff
{
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
webBuilder.ConfigureKestrel(serverOptions =>
{
serverOptions.Limits.KeepAliveTimeout = TimeSpan.FromSeconds(5);
});
});
}
}
我一直在阅读这篇微软文章:
Kestrel 选项 Kestrel Web 服务器具有约束配置 在面向 Internet 的部署中特别有用的选项。
对 KestrelServerOptions 的 Limits 属性设置约束 班级。 Limits 属性包含一个实例 KestrelServerLimits 类。
【问题讨论】:
标签: asp.net asp.net-core asp.net-web-api