Search code examples
iis.net-coreweb-configiis-express

Is it possible to change web.config values based on the hosting environment, such as iisExpress


I am developing a .net core 3.0 web app with a very simple web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <serverRuntime uploadReadAheadSize="10485760" />
    </system.webServer>
</configuration>

However, I want to change the web.config file so that this configuration is active with iis, but not with iisExpress, where the permissions to change uploadReadAheadSize are locked. Surely there must be a simple way to do this, but all my googling hasn't given me a straightforward answer


Solution

  • Due to the design, there seems to be no way to tell from within web.config whether the hosting server is IIS or IIS Express.

    But because IIS and IIS Express use different configuration file path, you can move such configuration elements from your web.config file to the desired applicationHost.config file.