Setting Asp.Net Core Environment Variables via web.config in IIS

Georg Dangl by Georg Dangl in Continuous Integration Thursday, June 09, 2016

Thursday, June 09, 2016

Posted in DotNet IIS

Since RC2, hosting .Net Core apps within IIS is no longer using the common HttpPlatformHandler as with any other processes but instead the ASP.NET Core Module for Windows Server Hosting.

While not a lot has changed, the Xml schema for the web.config elements is new, so you need to specify environment variables the following way in your main web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" forwardWindowsAuthToken="false" stdoutLogEnabled="true" >
      <environmentVariables>
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
      </environmentVariables>
    </aspNetCore>
  </system.webServer>
</configuration>

Alternatively, you can still use regular web.config transformations for publishing to IIS (there's currently no support for that in dotnet-publish-iis), for example in your web.Production.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.webServer>
    <aspNetCore>
      <environmentVariables xdt:Transform="Insert">
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" />
      </environmentVariables>
    </aspNetCore>
  </system.webServer>
</configuration>

 


Share this post


comments powered by Disqus

About me

Hi, my name's George! I love coding and blogging about it. I focus on all things around .Net, Web Development and DevOps.

DanglIT

Need a consultant for BIM, GAEB or Software Development?

Contact me at [email protected], +49 (173) 56 45 689 or visit my professional page!

Dangl.Blog();
// Just 💗 Coding

Social Links