

Creating Virtual Applications in Azure Web apps
Creating Virtual Applications in Azure Web Apps
Hi All,
Today’s focus is on Creating Virtual Applications in Azure Web Apps. I’ll guide you through deploying multiple web applications or APIs to a single Azure Web App using Virtual Applications. While similar setups can be achieved with IIS, let’s explore how Azure Web Apps streamline this process for optimal efficiency.
The Process
I have already deployed my Web App, which is based on .NET 7. This is a clean web app without any other applications.
Azure Web App Configuration
We need to configure a few settings in the web app. On the left-hand side, select Configuration.
You will be presented with the Configuration page. Select Path Mappings as shown in the image below.
Next, click on New virtual application or directory.
You will then be presented with the New Application or Directory page. In the image below, I have typed in /api2
for the Virtual Path and site\api2
for the Physical Path. You will need to change this to your application name, or if you are following along, use api1
first and then repeat for api2
.
Make sure the Directory checkbox is not checked. Then click OK.
Below is what the final setup should look like:
Enabling Basic Authentication and FTP
I enabled Basic Authentication and FTP credentials (even though I don’t need FTP, I wanted to show how to enable it). Since I will be deploying my code using Visual Studio 2022, I need Basic Auth enabled.
To enable this, go to General Settings and enable Basic Auth and FTP, as shown below:
Creating the Virtual Application Directories
We now need to create the directories. Microsoft does not do this automatically, so we must manually create them.
Go to Advanced Tools on the left-hand menu.
Click Go on the page that appears:
A new tab will open. From the Top Navigation Menu, click Debug Console and select PowerShell.
Navigate to the site
folder.
Inside this folder, create two new folders: api1 and api2.
To create them:
- Click the + icon.
- Select New Folder.
- Name it
api1
. - Repeat the process for
api2
.
The final result should look like this:
Publishing from Visual Studio 2022
Now that our Azure Web App setup is complete, we can publish our applications.
I created two new .NET 7 Web API projects using Visual Studio. Then, I created a new Publish Profile based on Azure:
After creating the profile, click Show all settings.
Go to Connection and update the Site name by appending the virtual application name (e.g., api1
).
Before:
After:
Click Save once done.
Time to Publish
Now, we can publish our apps. Click the Publish button.
After publishing, I visited:
https://virtualappdemo.azurewebsites.net/api1
Since this is an API, I received a 404 error, which is expected. To test, I accessed an endpoint directly:
https://virtualappdemo.azurewebsites.net/api1/weatherforecast
Publishing the Second App
I followed the same steps to publish api2
, but I encountered the following error:
HTTP Error 500.35 - ANCM Multiple In-Process Applications in same Process
To fix this, I added the following line to the .csproj file of the second project:
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
Final .csproj
file:
<PropertyGroup> <TargetFramework>net7.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel></PropertyGroup>
After republishing, I encountered a new error:
HTTP Error 500.34 - ANCM Mixed Hosting Models Not Supported
The issue occurs because you can’t mix hosting models. The first app was running in In-Process, while the second was running Out-Of-Process.
To resolve this, I added the same setting to the first project:
<PropertyGroup> <TargetFramework>net7.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel></PropertyGroup>
Once republished, everything worked as expected:
https://virtualappdemo.azurewebsites.net/api2/weatherforecast
Additional Resources
That’s all, folks! 🚀 Hope this guide helps.
← Back to blog