Search code examples
web-applicationsenvironment-variablesazure-web-app-serviceappsettings

Azure App Service - Why App Service environment variables doesn't work for virtual directory?


I have two web apps deployed in a single Azure App Service instance:

  1. The first one has a home directory in "site\wwwroot".
  2. The second (api) has a home directory in "site\wwwroot\wwwroot".

I created a new virtual application in the app service - path mappings. I set a name and I set a physical path to:
site\wwwroot\wwwroot

I also set multiple environment variables (App settings) in the app service to override the default ones in the appsettings.json files of the both web apps:

  1. site\wwwroot\appsettings.json
  2. site\wwwroot\wwwroot\appsettings.json

Now the env. variables from the app service are overriding the variables in the first web app (site\wwwroot\appsettings.json). However the override of the variables of the second app (site\wwwroot\wwwroot\appsettings.json) is not working.

Does Azure App Service environment variables also override app. settings from the virtual application or what am I missing here?


Solution

  • Does Azure App Service environment variables also override app. settings from the virtual application

    Yes, you can override app settings of the virtual application using Environment Variables.

    Refer my SOThread to deploy Virtual Applications to single Azure App Service.

    • I am able to override the settings for both Main and Virtual application.

    My application folder structure:

    enter image description here

    • Your Virtual application has to be deployed to the site/wwwroot main directory.

    enter image description here

    • If you have same key in both the Apps, and if you set the key in App Service Environment Variables, both the applications value will be updated.

    enter image description here

    • I have set the same key with name CommonKey in both the apps, you can see that it is overriding the value in 2 applications.

    Output:

    enter image description here

    • To avoid confusion, make sure the key names are different for both the apps.