In this post, we will look at how to configure virtual applications with App Services and API Management (APIM) in Azure.
Let’s continue with the example here, where we created the CarlCRMAPI app service using .NET Core.
Go to https://portal.azure.com and select the App Service. Then go to Configuration->Path Settings->Virtual Path:
We see the path is set to wwwroot:
Under Overview, stop the service:
Let’s head over to Kudu:
Go to Debug Console->Cmd and select the Site folder:
Rename the wwwroot to wwwroot_NEW using the command:
ren wwwroot wwwroot_NEW
Start the Service again in Overview.
Now, if we try to access the server, we get an error:
“The page cannot be displayed because an internal server error has occurred.”
Let’s go back to the Configuration->Path mappings and select Edit:
Change the physical path to wwwroot_NEW:
And click Save:
We now get data returned:
Great.
Now let’s try another scenario. What if we wanted this app service to support multiple folders and services? Let’s create a new folder, e.g. wwwroot_DEV, and have our app service point to that folder through a virtual path.
Let’s create a new virtual application:
Copy the existing wwwroot_NEW folder using dos to a new folder called wwwroot_DEV. We will do this for this demo so we can be up and running with 2 services quickly. In reality you would build your 2nd service and deploy it properly to this new application folder.
xcopy /E /I wwwroot_NEW wwwroot_DEV
Virtual path = DEV
Physical path = site\wwwroot_DEV
Uncheck directory:
We now have:
Save and restart the App Service.
Now if we browse to the service URL and add a /DEV, we get the data returned:
Awesome.
Now, what if we want our APIM to recognize these two services?
Our original APIM that we created which points to the App Service still works. If we send through the request through the developer portal, we get a good response back:
Let’s go to APIs and add a new API:
We will add DEV to the URL, and the Display Name and Name:
If we try to save this, we get:
Cannot create API ‘carl-crm-api-dev’ with the same Path ” as API ‘carl-crm-api’ unless it’s a part of the same version set
Add DEV to the API URL Suffix and click Create:
We now see:
In the Developer Portal, we have:
Sending the request, we get “backend service URL is not defined”:
In the Settings of the APIM API, enter the URL of the App Service, with the DEV virtual path:
We now get a response back:
Now we can deploy to the 2 different folders and have 2 different app services.
I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.
IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.
THANK YOU, AND LET'S KEEP LEARNING TOGETHER.
CARL
This is a nice one. Thanks. But I was wondering if we would want to automate this rather than using Kudu console, how would we do it. Say for example, I would want my code which is hosted in storage account to be uploaded to a new sub directory under wwwroot. How can I automate that using the cli or powershell?
Now when we deploy to virtual path, root application gets messed. Error looks like some it methods in the dll file can not be extracted.