Quick question. How can I get the name of the azure environment name (Production/Staging/QA) at run time in .net core? I tried System.Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") and System.Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT"). The first ASPNETCORE_ENVIRONMENT only returns the environment when it runs locally.
Asked
Active
Viewed 1,367 times
0
-
Why do you need it? What are you trying to do differently when on prod/staging/QA environment? – Anand Sowmithiran Apr 03 '22 at 17:04
-
1WEBSITE_SLOT_NAME environment variable will indicate the deployment `slot`, it may help you. Depends on how you manage your dev/QA environments. – Anand Sowmithiran Apr 03 '22 at 17:16
1 Answers
1
- Use the below line of code to get the Environment name in Azure
var slot = System.Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", EnvironmentVariableTarget.Process);
- Add the Application settings in Configuration section of your Web App.

Harshitha Veeramalla
- 1,515
- 2
- 10
- 11