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

asp.netasp.net-coreciis

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.

Best Answer

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.