Overriding Environment Variables in ASP.NET Core

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">	<environmentVariables>		<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="development" />	</environmentVariables>	</aspNetCore>

Leave a comment

Please note that we won't show your email to others, or use it for sending unwanted emails. We will only use it to render your Gravatar image and to validate you as a real person.