6

I am having a slight (though, not impacting functionality) issue with Azure App Service and the ASPNETCORE_ENVIRONMENT. On my local development environment I used the command setx ASPNETCORE_ENVIRONMENT "Development" to set my local to Development. When I output the value of Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") in my local it correctly returns "Development" and correctly selects the proper Development appSettings JSON file. So far so good.

Here is where things get weird (or maybe it's correct?). In Azure App Service I set the ASPNETCORE_ENVIRONMENT value within the Application Settings portion to "Production". When I output this value in the application it says "Production;Development". I was expecting "Production". The application is correctly pulling the production appSetting values, but why am I seeing both values? I was able to adapt my code to check if the value .Contains("Production") for production specific functionality, but I cannot figure out why both values are present. I have researched thoroughly and cannot find a reason. My solution and project files have no variables set. My Azure Build/Pipline has no variables set for this.

Any thoughts?

0xElGato
  • 353
  • 2
  • 10

1 Answers1

13

This ended up being caused by a process adding a "Web.config" file and pre-populating it with ASPNETCORE_ENVIRONMENT. Removing the value from the Web.config worked. I have since then been only setting environment values on the machines/systems/cloud apps.

0xElGato
  • 353
  • 2
  • 10
  • 1
    Your tip helped! I was pulling my hair out trying to figure out why my Azure App Services "Release" deployment was still starting up in "Development" mode. Never occurred to me to look in web.config. – Martin_W Jun 09 '20 at 06:37
  • 1
    Awesome! That's exactly why I posted the answer, hoping it helped one person some day! Eventually my Visual Studio stopped adding that in. Not sure why it was happening. – 0xElGato Jun 09 '20 at 13:12
  • 1
    Mint! The Auth0 generated code for testing .net core 3.1 came through with a "Web.config" and "Development" mode set. Once I removed the Web.config file from my vs 2019 project the ASPNETCORE_ENVIRONMENT was applied correctly. – BusyBee Nov 01 '20 at 21:31
  • Looked everywhere and was not able to get my head around this. Thanks, this worked like a charm! – OhmnioX Dec 05 '20 at 09:28