This article is contributed. See the original author and article here.

After upgrading the asp.net core application to asp.net core 3.1 version, application is not able to read the “ASPNETCORE_ENVIRONMENT” variable from local environment and getting defaulted to web.config values.

 

ASPNETCORE_ENVIRONMENT value is set as Development in Web.config.

 

Ramchandra_Kudtarkar_0-1599855254632.png

 

 

ASPNETCORE_ENVIRONMENT value is set as Production in local environment of Azure App Service application setting.

 

Ramchandra_Kudtarkar_1-1599855254635.png

 

 

ANCM is Preferring value set in Web.config over the local environment variable in Azure App service application setting.

 

Ramchandra_Kudtarkar_2-1599855254638.png

 

 

Solution:

 

We need to add a switch “ANCM_PREFER_ENVIRONMENT_VARIABLES” and set as “true”  to allow ANCM to prefer the local environment over the Web.config values. Below is the screenshot of app service app settings.

 

Ramchandra_Kudtarkar_3-1599855254640.png

 

If the switch is added in both Web.config and local environment and both of them are set to “true” then web.config “ASPNETCORE_ENVIRONMENT” will take precedence.

 

After setting “ANCM_PREFER_ENVIRONMENT_VARIABLES” as “true” in App service App settings, ANCM is preferring the local environment variable “ASPNETCORE_ENVIRONMENT” which is set to production .

 

Ramchandra_Kudtarkar_4-1599855254642.png

 

For more information about these changes, please refer below Github issues.

https://github.com/dotnet/aspnetcore/pull/20006

https://github.com/dotnet/aspnetcore/issues/19450

Brought to you by Dr. Ware, Microsoft Office 365 Silver Partner, Charleston SC.

%d bloggers like this: