Azure doesn't respect env setting

saigkill 21 Reputation points
2021-08-12T09:59:50.123+00:00

Hello,
i've just created a Webapp (Website) on Azure. In portal i added that environment setting: ASPNETCORE_ENVIRONMENT = Production.

Inside Kudu it shows me, that it are set (looks for me).

  • APPSETTING_ASPNETCORE_ENVIRONMENT = Production
  • ASPNETCORE_ENVIRONMENT = Production

In my net 5 code i'm using on the Layout file:

122723-screenshot-2021-08-12-115744.png

If i'm accessing the site, i can see in browsers source view, that it uses the "Development" env. And a @_env.EnvironmentName (where _env comes from Microsoft.AspNetCore.Hosting.IWebHostEnvironment) returns also "Development".

I'm reading the environment settings in my Program.cs:

builder.SetBasePath(ctx.HostingEnvironment.ContentRootPath)  
        .AddJsonFile("config.json", false, true)  
        .AddUserSecrets(Assembly.GetEntryAssembly())  
        .AddEnvironmentVariables();  

Maybe i have to set another setting, so Azure identifies itself as Productive?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,910 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 22,416 Reputation points Microsoft Employee
    2021-08-13T19:42:04.827+00:00

    From Azure WebApps stand-point (tag - azure-webapps) - As AgaveJoe mentioned, the default value is (Production).
    On App Service, for ASP.NET Core (also ASP.NET ), setting app settings are like setting them in <appSettings> in Web.config or appsettings.json, but the values in App Service override the ones in Web.config or appsettings.json.

    Just to highlight, The ASPNETCORE_ENVIRONMENT environment variable can be added to web.config to run the app in the Development environment. As long as the environment isn't overridden in app startup by UseEnvironment on the host builder, setting the environment variable allows the Developer Exception Page to appear when the app is run.

    See this doc for more details - ASP.NET Core reads from the following environment variables.

    Also, as a side note that setting the environment variable for ASPNETCORE_ENVIRONMENT is only recommended for use on staging and testing servers that aren't exposed to the Internet.

    0 comments No comments