ASP.NET Core uses ASPNETCORE_ENVIRONMENT to identify the hosting environment for an application. WebApplicationBuilder reads the variable and exposes the result through WebApplicationBuilder.Environment and IHostEnvironment.EnvironmentName. section 10.4.1
Use the environment name to select behavior and configuration appropriate to where the application runs.
- Prefer Development, Staging, and Production; other values are allowed, but these have built-in helper methods. section 10.4.1
- Check environments with IsDevelopment(), IsStaging(), IsProduction(), or IsEnvironment(string), which perform case-insensitive comparisons. section 10.4.1
- If ASPNETCORE_ENVIRONMENT is unset, ASP.NET Core assumes Production; locally, launchSettings.json can scope the variable to a project. section 10.5
- DOTNET_ENVIRONMENT is also supported, but ASPNETCORE_ENVIRONMENT takes precedence when both variables are set. section 10.4.1
Selecting a local environment
Set ASPNETCORE_ENVIRONMENT to Development while running locally. The application then exposes Development as EnvironmentName, allowing environment-specific files such as appsettings.Development.json to be selected. section 10.4.1 section 10.5
IHostEnvironment also identifies the application’s content root, where configuration files are found. The web root is separate: WebRootPath, typically wwwroot, identifies browser-accessible static files. section 10.4.1

