According to this article from Microsoft, "Production is the default value if DOTNET_ENVIRONMENT and ASPNETCORE_ENVIRONMENT have not been set. Apps deployed to Azure are Production by default." I did not have those values set in the configuration of my Azure App Service, yet in my injected IConfiguration in code I am seeing a value from appsettings.Development.json
instead of appsettings.json
. I also tried explicitly setting ASPNETCORE_ENVIRONMENT equal to "Production", but the result is the same. What am I doing wrong?
2
Answers
I have discovered the issue. I also had the environment variables set in the
web.config
from a long time ago (pre-Azure). Removing these old values fixed the problem.Yes, the
ASPNETCORE_ENVIRONMENT
after deploying the Web App to Azure App Service will be Production.ASPNETCORE_ENVIRONMENT
value in.cshtml
page.Environment Output:
appsettings.Development.json
file..cshtml
page using the below code.Local Output:
Deployed App Output:
As I have set the same in
appsettings.json
, the value fromappsettings.json
file is loaded.appsettings.json
file does not have the above setting, then the value will be null.json
file inProgram.cs
as below, only that file values will be loaded.Make sure you have not set the
json
file as mentioned above.