Overriding Environment Variables in ASP.NET Core

Posted by Blake on 11/28/2016

There maybe instances where you need to set or override an environment variable for an ASP.Net core site outside of the server administration area (IIS, Azure console, etc.). This can be accomplished by making an entry to the "aspNetCore" section of the web.config.

In the below example I am going to override the environment variable that specifies the environment.

XML for web.config

      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    <aspNetCore processPath=".\Apps.MySite.exe" arguments="" stdoutLogEnabled="true" stdoutLogFile=".\logs\mysite-stdout" forwardWindowsAuthToken="false">
			<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="development" />