Carlos Garcia
Carlos Garcia

Reputation: 2970

change DotNet 6 inbound request timeout

I need to ensure a synchronous request stay alive for over 60 minutes. Is there a way to change the default inbound request timeout in DotNet 6?

I found this:

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

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

But not sure where to get serverOptions in my Program.cs

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();

Upvotes: 3

Views: 15815

Answers (1)

Brando Zhang
Brando Zhang

Reputation: 28257

According to your description, I suggest you could try to modify it by changing the program.cs file codes:

More details, you could refer to below codes:

var builder = WebApplication.CreateBuilder(args);

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

Upvotes: 4

Related Questions