We have so many clients experience this issue when deploying their ASP.NET Core application. I hope this tutorial can help you if you experience same issue.
In this post, we see two different causes of this error, two different solutions for the first cause, a solution for the second cause, and learn what needs to be in web.config
for ASP.NET Core to operate.
Error Message
Here is a screenshot of the HTTP Error 502.5 - Process Failure
error. You’ll see this, in your browser, when making a request to your ASP.NET Core application, after deployment, if you have this issue.
Solution to Fix the Error
There are 3 solutions to fix above error.
1. Make sure you have installed .NET Core Runtime
The most common reason for this to occur is when you haven’t installed the .NET Core runtime on the server.
You can download the latest .NET Core runtime from Microsoft’s .NET download page.
For Windows, you’ll usually want the latest .NET Core runtime (now already .NET 5), as highlighted in the following screenshot:
This will get you the Windows Hosting Bundle Installer, which will install both the x86 and x64 runtimes on Windows Server.
2. Publish it as a Self-Contained Deployment
If you don’t want to install the .NET Core Runtime. An alternative for .NET Core web applications is to publish them in the Self-Contained
deployment mode, which includes the required .NET Runtime files alongside your application.
You can select this option from the advanced publish settings screen in Visual Studio:
If you go with this option, you’ll also need to choose a target runtime: win-x86, win-x64, osx-x64, or linux-x64. Because self-contained deployments are not portable.
3. Transform your web.config file
Another reason for this error to occur is when you deploy an untransformed web.config
file.
This is likely to be your issue if you had a previously working web application and merely deployed a new version of it.
Check your ASP.NET Web Config
In ASP.NET Core applications, the web.config
file contains a handler that directs requests to the AspNetCoreModule
and an aspNetCore
element that defines and configures the ASP.NET Core process to execute your web application.
Here is a minimal web.config
file for an ASP.NET Core application:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
Note that it’s possible that you don’t have a web.config
file in your ASP.NET Core project. If you do not, one will be generated for you when publishing the project, as IIS and IIS Express require a web.config
file when hosting an ASP.NET Core web app.
Issue
The untransformed web.config
contains the variables %LAUNCHER_PATH%
and %LAUNCHER_ARGS%
rather than the correct paths. When IIS tries to run ASP.NET Core, it uses %LAUNCHER_PATH%
and %LAUNCHER_ARGS%
rather than the correct path and arguments.
To fix the HTTP Error 502.5 in ASP.NET Core, you need to transform the web.config
and replace the untransformed web.config
file on the IIS web server.
How to Change Web.Config?
This transformation takes place when you choose to publish
your web application. The transformed web.config
ends up in the published output folder. Therefore, you simply need to publish
your web application and copy the resulting web.config
file onto the server.
In a transformed web.config
file, the aspNetCore
element will look something like this:
<aspNetCore processPath="dotnet" arguments=".\MyApplication.dll" stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
%LAUNCHER_PATH%
has been replaced by dotnet
and %LAUNCHER_ARGS%
has been replaced by the path to the main web application dll .\MyApplication.dll
.
Conclusion
I hope the article above can help you to overcome the 502 error. There are still many errors that you can encounter when publishing the Asp.net core application. And we will certainly continue to provide interesting tutorials about Asp.net.
If you are looking for quality Asp.net hosting, you can directly visit our website at https://www.asphostportal.com. We always support the latest Asp.net version.
Andriy Kravets is writer and experience .NET developer and like .NET for regular development. He likes to build cross-platform libraries/software with .NET.