更改 DotNet 6 入站请求超时

change DotNet 6 inbound request timeout

我需要确保同步请求保持活动状态超过 60 分钟。 有没有办法更改 DotNet 6 中的默认入站请求超时?

我发现了这个:

serverOptions.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(60);

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

但不确定在我的 Program.cs

中从哪里获取 serverOptions
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

根据你的描述,我建议你可以尝试修改program.cs文件代码:

更多详情,您可以参考以下代码:

var builder = WebApplication.CreateBuilder(args);

builder.WebHost.UseKestrel(options =>
{
    options.Limits.MaxConcurrentConnections = 100;
    options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(60);
});