Search code examples
azureenvironment-variablesazure-web-app-serviceapp-service-environment

Azure App Service configuration settings (environment variable) does not work


I created an environment variable in Azure App Service. However, I'm not able to pick the value from Azure while it is published.

So I added it to the appsettings.json, and it works.

My question would be, if I add an environment variable in Azure configuration settings, shall I add it in the appsettings.json as well, or is having it in the Azure environment settings enough?

enter image description here

When I navigate to

https://your-web-name.scm.azurewebsites.net/Env.cshtml

I can clearly see the variable is present there. Why is this not being picked up in the code? Am I doing something wrong?

appSettings["MailKitPassword"] <-- This is not being picked up, so I have to hard-code it.

Solution

  • In order to retrieve it you should use Environment.GetEnvironmentVariable("APPSETTING_MailKitPassword")