Runtime environment management

ASP.NET Core introduces improved support for controlling application behavior across multiple environments, such as development, staging, and production. Environment variables are used to indicate which environment the application is running in, allowing the app to be configured appropriately.

Refer to Use multiple environments in ASP.NET Core for information on how to leverage ASP.NET Core to management Sitecore development, staging and production environments. 

ASP.NET Core references ASPNETCORE_ENVIRONMENT, an environment variable, to describe the environment that the application is currently running in. This variable can be set to any value, but there are three conventional values: Development, Staging, and Production. These values are used in the samples and templates provided with ASP.NET Core.

The current environment setting can be detected programmatically from within your application. In addition, you can use the Environment tag helper to include certain sections in your view based on the current application environment.

Note: the environment name is not case sensitive.

When developing an application, use the ASPNETCORE_ENVIRONMENT. When using Visual Studio, this setting can be specified in your project’s debug profiles. For example, for IIS Express:

RuntimeEnvironmentManagement.png

A staging environment is a pre-production environment that is used for final testing before deployment to the production environment. Ideally, the physical characteristics of the staging environment should mirror the production environment, so that any issues that could occur in the production environment occur first in the staging environment, where they can be addressed without impact to users.

The production environment is the environment in which the application runs when it is live and being used by end users. This environment should be configured to maximize security, performance, and application robustness. Some common actions that would be involved in a production environment that would differ from a development environment include:

  • Caching is turned on.

  • All client-side resources are bundled, minified, and potentially served from a CDN.

  • Diagnostic ErrorPages are turned off.

  • Friendly error pages are turned on.

  • Production logging and monitoring is enabled. For example, Application Insights.

Avoid scattering environment checks throughout your application. Instead, perform environment checks in the Startup classes of the application whenever possible.