ASP.NET Core deployed on IIS returns 502 Error for long running requests

12,204

Solution 1

By default, ASP.NET Core request time out is 2 minutes, and you can change it via requestTimeout in setting file. See more here

requestTimeout Optional timespan attribute.

Specifies the duration for which the ASP.NET Core Module will wait for a response from the process listening on %ASPNETCORE_PORT%.

The default value is "00:02:00".

The requestTimeout must be specified in whole minutes only, otherwise it defaults to 2 minutes.

Solution 2

I am getting same error when data is huge and take more time to execute web page, I have changed timeout value for .netcore in 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>

I have add requestTimeout="00:20:00" in my existing web.config file and it works.

for reference go to this url

Share:
12,204

Related videos on Youtube

jacksparrow92
Author by

jacksparrow92

Updated on July 03, 2022

Comments

  • jacksparrow92
    jacksparrow92 almost 2 years

    I have an ASP.NET Core 2 web application which is hosted on IIS 10 on Windows Server 2012 without any load balancing and special configurations. For some MVC actions which takes too long we get a 502 HTTP error.

    enter image description here

    After seeing this error I was shocked, because I didn't have any configuration for a proxy server, etc. And then I remembered that the ASP.NET Core runs on Kestrel. So I came to this conclusion that here IIS plays the role of the proxy server and forwards the requests to the Kestrel. So I think this is somehow related to a timeout configuration, as the other parts of the application works very well. I have searched for similar questions on SO but no luck finding a solution.

    • CodeCaster
      CodeCaster about 6 years
    • Dmitry Pavlov
      Dmitry Pavlov about 6 years
    • Chris Pratt
      Chris Pratt about 6 years
      Long-running tasks should be run in the background, especially if it takes so long that the request is timing out. You can use something like Hangfire or in ASP.NET Core 2.0, you can use IHostedService. In either case, your action should schedule the task and then return immediately. You can then use SignalR to monitor the status and update the user when the task has completed.
    • jacksparrow92
      jacksparrow92 about 6 years
      @ChrisPratt Thank you Chris for that point. I will check it out.
  • War
    War over 3 years
    Any other ideas ... this doesn't fix my problem, request is clearly timing out will under the configured length of time with the same error.