3

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

Brando Zhang
  • 22,586
  • 6
  • 37
  • 65
Carlos Garcia
  • 2,771
  • 1
  • 17
  • 32

1 Answers1

4

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);
});
Brando Zhang
  • 22,586
  • 6
  • 37
  • 65
  • I used that UseKestrel() inside of default Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder =>{}) and it didn't changed default timeout. It's still 20 seconds – chalwa Oct 14 '22 at 13:19