Why Increase Request Timeout in ASP.NET Core Application?

Views: 21315
Comments: 1
Like/Unlike: 1
Posted On: 26-Jan-2019 07:51 

Share:   fb twitter linkedin
Rahul M...
4822 Points
23 Posts

If your application using ASP.NET Core 2.0 API and hosted to an Azure App Service, then you might run into an issue where it takes a process request longer than two minutes to complete. You’ll typically get a 502 Bad Gateway error from IIS server with the following info:

"The specified CGI application encountered an error and the server terminated the process"

If you check your diagnostic logfiles (i.e application insights or other server logs or nlog) then you may see:

18-01-19 03:47:03.232 +00:00 [Error]
An unhandled exception has occurred while executing the
requestSystem.Threading.Tasks.TaskCanceledException: A task was canceled.

In previous versions of ASP.NET MVC you can increase the timeout in your asp.net controller action.

HttpContext.Current.Server.ScriptTimeout = 90000;

But this doesn't exist in ASP.NET Core.

In ASP.NET Core, you can just add web.config to your project and specify this (and other) setting value:
Setting the RequestTimeout="00:20:00"
in the aspNetCore tag and will resolve the above timeout issue.


<?xml version="1.0" encoding="utf-8"?>
   <add name="aspNetCore" path="*" verb="*"
  <aspNetCore requestTimeout="00:20:00"


If a web.config file does not present in the project, the file can be created with the correct processPath and arguments to configure the ASP.NET Core Module and moved to published output. In VS 2017, you can create web.config with default settings by add new items wizard and then uncomment the required settings.


great man...

01-Feb-2019 at 23:01
 Log In to Chat