In Visual Studio 2015 you set the following variable in project properties: ASPNET_ENV. If you set it to development then you can use:
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseErrorPage();
}
}
IsDevelopment method will check ASPNET_ENV environment variable. Now this is all good on development while you are in Visual Studio 2015. When you publish the web application to IIS on a production server how can you set the value for ASPNET_ENV?
My server is Windows Server 2012
This is how to set the environment variable on Windows:
ASPNET_ENV
(RC1) or ASPNETCORE_ENVIRONMENT
(RC2, RTM and Above) and a value of Production
, Staging
, Development
or whatever you want.See also this answer for how to read the environment variable from gulpfile.js.
If you are using IIS to host your application, it's possible to set the environment variables in your web.config
file like this:
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="QA" />
<environmentVariable name="AnotherVariable" value="My Value" />
</environmentVariables>
</aspNetCore>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With