【问题标题】:Is is possible to set the "aspNetCore requestTimeout" value.........via "code" with Kestrel?是否可以通过 Kestrel 的“代码”设置“aspNetCore requestTimeout”值……?
【发布时间】:2020-06-23 16:31:32
【问题描述】:

是否可以通过 Kestrel 的“代码”设置“aspNetCore requestTimeout”值(参见下面的 xml).........?

我在 KestrelServerLimits 对象上找不到任何东西。

https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.server.kestrel.core.kestrelserverlimits?view=aspnetcore-3.1

以下是 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);
                    });

                });
    }
}

我一直在阅读这篇微软文章:

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-3.1#kestrel-options

Kestrel 选项 Kestrel Web 服务器具有约束配置 在面向 Internet 的部署中特别有用的选项。

对 KestrelServerOptions 的 Limits 属性设置约束 班级。 Limits 属性包含一个实例 KestrelServerLimits 类。

【问题讨论】:

    标签: asp.net asp.net-core asp.net-web-api


    【解决方案1】:

    没有。 This GitHub issue 说:

    没有办法强制终止 .NET 任务。这就是为什么我们不能自己停止失控的 CPU 进程。

    requestTimeout in web.config 是 IIS 的超时,它将停止等待来自您的 webapp 的响应并向客户端返回 500 错误,但您的网络服务器 (Kestrel) 将继续处理请求。并且没有人可以中断它(只有重新启动 kestrel 进程会有所帮助),这就是为什么 kestrel 中没有这样的配置设置。

    【讨论】:

    • 现在我想知道为什么 anyone 使用 Kestrel 作为 ASP.NET Core 的终端主机。没有超时会消除生产环境中一个非常重要的安全阀,有时可能会遇到意外行为。这个设计就像使用connection.CommandTimeout = 0一样出色。
    • 呃。似乎只有使用 IIS out of process 模型才支持请求超时。
    猜你喜欢
    • 2016-01-29
    • 2017-03-23
    • 2016-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-21
    • 1970-01-01
    相关资源
    最近更新 更多