Increase the timeout of .NET/.NET Core Applications
Increase Request Timeout: Timeouts with long running ASP.NET Core/.NET Controller methods.
If you’re using ASP.NET Core 2.x/3.x and .NET 5.x API and deploying to an Azure App Service, then you might run into an issue where it takes a process request longer than 2 minutes to complete. You’ll typically get a 502 Bad Gateway
with the following info:
"The specified CGI application encountered an error and the server terminated the process".
If you check your diagnostic logfile you might see:
018-06-15 03:47:03.232 +00:00 [Error] Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: An unhandled exception has occurred while executing the request
System.Threading.Tasks.TaskCanceledException: A task was canceled.
No, there is not way to set request timeout in asp.net core hosted in IIS from C# code.
But according to the documentation you can just add web.config to your project and specify this (and other) setting value: Setting the RequestTimeout="00:20:00"
on the aspNetCore
tag and deploying the site will cause it not to timeout.