502 bad gateway error response is not like traditional 500 error which is mostly a code problem, this makes it even difficult to troubleshoot the root cause and I also see quite a few confuse from developers that why there is 502 error in ASP.NET Core production environment.
Basically, the HTTP 502 Bad Gateway server error response code indicates that the web server (IIS in our scenario), while acting as a gateway or proxy, received an invalid response from the upstream server. This can happen for multiple reasons – for example, failure to connect to the upstream server, no response from the upstream server, or the up steam server took too long to respond (timeout). As a result, the server which is acting as a gateway or proxy will report that as a status of 502. The reason why 502 is difficult to troubleshoot is that the root cause could vary a lot and will be dependent on real application framework, such as Asp.Net, PHP, Java etc.
For ASP.NET Core application, as we know, in order to host the application in IIS, we need to install AspNetCoreModule. It is actually a native module in IIS acting as a reverse proxy for dotnet core application, that’s why we may experience 502 error for ASP.NET Core application.
Though 502 error could also be caused by underlying platform issue such as disk/storage problem, in most condition, we need to focus on the components running in the upstream server (root cause), and IIS log will give us information about how to narrow down the issue.
Now, suppose we experience 502 error when accessing an ASP.Net Core application, the sub status code might not be helpful enough. Firstly, we can have a check for the IIS log and verify the root cause by sc-win32-status code. Alternatively, we can enable Failed Request Tracing to know more details.
The above log gives us two import information, the error comes from AspNetCoreModule and the error code is 2147954402. That means, the 502 error is fired by AspNetCoreModule and it probably has experienced some invalid response. Furthermore, we can use either err utility or visit http://errors/ to figure out 2147954402 is just WININET_E_TIMEOUT. By default, ASP.NET Core request timeout is 2 minutes, and we can change it via requestTimeout in setting file.
No #1 Recommended ASP.NET Core Hosting
ASPHostPortal.com is the leading provider of Windows hosting and affordable ASP.NET MVC Hosting. ASPHostPortal proudly working to help grow the backbone of the Internet, the millions of individuals, families, micro-businesses, small business, and fledgling online businesses. ASPHostPortal has ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch, ASPHostPortal guarantees the highest quality product, top security, and unshakeable reliability, carefully chose high-quality servers, networking, and infrastructure equipment to ensure the utmost reliability.
HostForLIFE.eu guarantees 99.9% uptime for their professional ASP.NET MVC hosting and actually implements the guarantee in practice. HostForLIFE.eu is the service are excellent and the features of the web hosting plan are even greater than many hosting. HostForLIFE.eu offer IT professionals more advanced features and the latest technology. Relibility, Stability and Performance of servers remain and TOP priority. Even basic service plans are equipped with standard service level agreements for 99.99% uptime. Advanced options raise the bar to 99.99%. HostForLIFE.eu revolutionized hosting with Plesk Control Panel, a Web-based interface that provides customers with 24×7 access to their server and site configuration tools.
DiscountService.com.au is The Best and Cheap ASP.NET MVC Hosting. DiscountService.com.au was established to cater to an under served market in the hosting industry web hosting for customers who want excellent service. DiscountService.com.au guarantees the highest quality product, top security, and unshakeable reliability, carefully chose high-quality servers, networking, and infrastructure equipment to ensure the utmost reliability. DiscountService.com.au has ability to support the latest Microsoft and ASP.NET technology, such as: WebMatrix, WebDeploy, Visual Studio 2015, .NET 5/ASP.NET 4.5.2, ASP.NET MVC 6.0/5.2, Silverlight 6 and Visual Studio Lightswitch. DiscountService.com.au is devoted to offering the best Windows hosting solution for you.