Increase request timeout of ASP.NET Core API hosted in Azure App Service

If you are using ASP.NET Core 2.0 API and deploying to an Azure App Service, and if the process takes more than 2 minutes, then you will get 502 Bad Gateway response with the message "The specified CGI application encountered an error and the server terminated the process".

You can fix this by adding web.config file to your project -> uncomment <system.webServer> block and add requestTimeout="00:20:00" as shown below

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!-- To customize the asp.net core module uncomment and edit the following section. 
  For more info see https://go.microsoft.com/fwlink/?linkid=838655 -->
  
  <system.webServer>
    <handlers>
      <remove name="aspNetCore"/>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" requestTimeout="00:20:00"/>
  </system.webServer>
    
</configuration>

Happy Coding  😊!!

Gopikrishna

    Blogger Comment
    Facebook Comment

2 comments:

  1. First tell how to add a web.config file in the project/solution. Asp.Net Core add appsettings.json by default and not web.config. :)

    ReplyDelete
    Replies
    1. We can add web.config to .Net core project by right click on project -> Click on Add -> New Item -> Web -> Web Configuration File. :)

      Delete