Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to host multiple applications in the same Azure Web App Service?

I would to host two ASP.NET Core Applications, a Web API and a Blazor Server App, but I searched in the internet and the answers that I founded only target to a different path inside of one application, that's not my case. I would to use they like a sub-address of the same Azure Web App for example: www.example.com and www.example.com/api where each one will be a different .NET Core application. So I suspect that I'll need to create two Azure App Services and try to communicate they both, but maybe the structured that I wonder won't work in this way, it's that right? How I can do this?

like image 270
Lucimarck J S Dias Avatar asked Dec 23 '22 20:12

Lucimarck J S Dias


1 Answers

I have the same setup as you; an ASP.NET Core web API, and a Blazor Server Side app.

As you want to use the same domain for both services, you would have to use Azure API Management or some other proxy if you were to route requests to two different Azure App Services.

An easier option is to deploy both services to the same App Service, but as different virtual applications. You publish your Blazor app as normal, but for the Web API you would publish to a new virtual application /api.

To enable this virtual application, navigate to Configuration and then Path mappings in your App Service. Here you already have the default virtual application / pointing to site\wwwroot. You then add another virtual application named /api pointing to site\wwwroot\api:

Azure App Service Configuration

When adding the virtual application, remember to remove checkbox for Directory (making it a virtual application instead), and optionally enable Preload:

Add Virtual application to Azure App Service

If you publish your app using Azure DevOps Pipeline, it has an option to specify virtual application if another than default should be used.

You can now navigate to your two different URLs and hit each service. Note that when developing your Web API, you should not add api to your controllers routes, as this virtual application does that for you.

like image 199
Frode Evensen Avatar answered May 22 '23 17:05

Frode Evensen