Tutorial by Examples

For each environment you need to create a separate appsettings.{EnvironmentName}.json files: appsettings.Development.json appsettings.Staging.json appsettings.Production.json Then open project.json file and include them into "include" in "publishOptions" section. This lis...
All you need is a variable of type IHostingEnvironment: get environment name: env.EnvironmentName for predefined Development, Staging, Production environments the best way is to use extension methods from HostingEnvironmentExtensions class env.IsDevelopment() env.IsStaging() ...
This example shows how to configure multiple environments with different Dependency Injection configuration and separate middlewares in one Startup class. Alongside of public void Configure(IApplicationBuilder app) and public void ConfigureServices(IServiceCollection services) methods one can use C...
You may need to render some content in view, which is specific to some environment only. To achieve this goal you can use Environment tag helper: <environment names="Development"> <h1>This is heading for development environment</h1> </environment> <envi...
To set the environment to Development SET ASPNETCORE_ENVIRONMENT=Development Now running an Asp.Net Core application will be in the defined environment. Note There should be no space before and after the equality sign =. The command prompt should not be closed before running the application b...
When using PowerShell, you can use setx.exe to set environment variables permanently. Start PowerShell Type one of the following: setx ASPNETCORE_ENVIRONMENT "development" setx ASPNETCORE_ENVIRONMENT "staging" Restart PowerShell
If you do not want to use ASPNETCORE_ENVIRONMENT from environment variables and use it from web.config of your application then modify web.config like this- <aspNetCore processPath=".\WebApplication.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\lo...

Page 1 of 1