Why Increase Request Timeout in ASP.NET Core Application?

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

Share:   fb twitter linkedin
Rahul M...
Moderator
40 Points
15 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]
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware:
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.

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
  <handlers>
   <add name="aspNetCore" path="*" verb="*"
        modules="AspNetCoreModule"
        resourceType="Unspecified"/>
  </handlers>
  <aspNetCore requestTimeout="00:20:00"
              processPath="%LAUNCHER_PATH%"
              arguments="%LAUNCHER_ARGS%"
              stdoutLogEnabled="false"
              stdoutLogFile=".\logs\stdout"
              forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>

Note:

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.

 

1 Comments

Smith
great man...
  
 Log In to Chat