How to set the request timeout in C# .NET Core?

Normally we can easily set the request timeout in ASP.NET Core’s web.config file with following configuration.

<aspNetCore requestTimeout="00:01:00" />

But for the C# .NET Core applications we have to set that kind of timeout in service code under Program.cs file as below.

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup();
webBuilder.UseKestrel(option =>
{
option.Limits.KeepAliveTimeout = TimeSpan.FromMilliseconds(60000);
option.Limits.RequestHeadersTimeout = TimeSpan.FromMilliseconds(60000);
});

});

Leave a Reply

Your email address will not be published. Required fields are marked *