ameya
ameya

Reputation: 1668

ASP.NET Core 3.1 Host Sub application within main application

Let's say the main web app is: https:\mywebapp.com

Let's say I have separate Web API project and it has multiple services (api\service1, api\service2, )

For this I created 2 projects

  1. ASP.NET Core MVC Project for Main App - https:\mywebapp.com
  2. ASP.NET Core Web API project (Service 1, Service 2)

How should I set up my project and publish profile in Azure so that I have the following

  1. Main App (https:\mywebapp.com) - This is good I have publish profile and this gets published correctly in Azure
  2. Service 1 URL (https:\mywebapp.com\api\service1)
  3. Service 2 URL (https:\mywebapp.com\api\service2)

How do I achieve pt 2 and pt3 and have my web API project as a sub-app in my main web application? and share the same URL\api ?

Upvotes: 0

Views: 1529

Answers (1)

Joey Cai
Joey Cai

Reputation: 20127

You could create virtual directory on same azure web app.

When you first create Core MVC Project in azure webapp, go to Configuration > Path mappings and config the Virtual directory site/api.

enter image description here

When we publish the Core api to the Azure, we need to include the virtual directory path in the Site Name and Destination URL sections on the Connection tab.

enter image description here

Because Core 3.1 web api consists of one or more controller classes that derive from ControllerBase. The web API project template provides a starter controller:

[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase

So, we can visit it just with controllerName. And as it is sub directory, so the Url path is api\controllerName. Here is output:

enter image description here

Upvotes: 2

Related Questions