[Azure]:  HTTP Error 500.0 – ANCM In-Process Handler Load Failure

[Azure]: HTTP Error 500.0 – ANCM In-Process Handler Load Failure

With ASP.NET Core 2.2 support added to Azure Web Apps – it’s a bit tricky to host multiple applications using Virtual Directories. If you just publish your web apps using Visual Studio on different virtual, directories – not more than one will work at the time I’m writing this.

You need to make certain changes in order to get this working.

Let’s try publishing some asp.net core apps on Azure Web App in under virtual directories and see how it looks like. I’ve set up a Web App on Azure for this purpose with below configuration on Azure portal:

I’ve created an Empty ASP.NET Core Web App (Ver 2.2). My plan is to change the text and publish apps separately on the root directory, and on two different virtual directories, making three apps in total on one azure web app.

Startup.cs

My plan is to the default “Hello World” text to “App1 on Virtual Directory” and “App2 on Virtual Directory” subsequently and publish each on a different virtual directory. I will have to map two folders as virtual directories in order to get them working which can be done either before or after publishing the applications.

Downloading the Publish Profile helps quick publishing of azure web apps.

I added two virtual apps to the main apps at “/app1” and “/app2” virtual paths. So we have three apps now. Next I will publish the apps on the two virtual directories changing the default text.

I published the default application in Root Directory and it started saying “Hello World”, then I published the same app with changed text on App1 virtual directory but it failed to start with the following error, Same response for App2 on the next virtual directory. :

HTTP Error 500.0 – ANCM In-Process Handler Load Failure

Cause:
ASP.NET Core 2.2 and later has an In Process hosting model on IIS (set as default). In this model the app is hosted directly inside of an IIS Application pool (IISHttpServer Web Server), and it doesn’t proxy to an external dotnet.exe (instance running .NET Core native Kestrel Web Server).

.csproj file is where you can see the hosting model

Currently, only one app can run in one app pool (one azure app).

Solution:

Host the apps as OutOfProcess model

In this case – all the apps are required to be hosted as OutOfProcess model. When you publish the application it generates the web.config file with all the set configuration.

Open the .csproj file and under Project > PropertyGroup > AspNetCoreHostingModel, change the value “InProcess” to “OutOfProcess”. Be careful with the casing here!

change “InProcess” to “OutOfProcess” in .csproj file

Note that all the apps has to be deployed in “OutOfProcess” model, otherwise no application (inside the given azure app) will run. This change has to be applied in all the projects you’re publishing under one azure app.

My apps start working as I change the hosting model from InProcess to OutOfProcess and publish them.

This way it enables us to host multiple applications inside a single Azure Web App.

Note, that OutOfProcess drastically reduces the throughput as it proxies the request between Kestrel Web Server running dotnet.exe and IIS Web Server.

Leave a Comment

%d bloggers like this: