Question

I'm using Web Deploy (from VS2013) to publish an ASP.NET MVC site to an IIS 7.5.

I added some URL rewrite rules and custom HTTP response headers through IIS manager.

The problem is everytime I deploy a new version of the site, this extra configuration is deleted.

Is this the expected behaviour or is there something wrong? How can I keep these custom settings on each deploy?

UPDATE

So I understood I need to put these changes in the web.config. I'm trying to put them in the Web.Release.config but it's not being added to the deployed web.config. I guess I'm missing some XDT:Transform rule.

This is what I got in my Web.Release.config (yes, the publishing profile is using this Release config).

<configuration>
    <!-- some other stuff -->
    <system.webServer>
        <rewrite>
          <rules>
            <rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true">
              <match url="*" />
              <conditions>
                <add input="{HTTP_HOST}" pattern="mydomain.com" />
              </conditions>
              <action type="Redirect" url="http://www.mydomain.com/{R:0}" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
</configuration>
Was it helpful?

Solution 2

Ok so I understood I need to add this custom configuration in the web.config using XDT:Transform.

I added this to the Web.Release.config and it worked:

<system.webServer>
    <rewrite xdt:Transform="Insert">
      <rules>
        <rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true">
          <match url="*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="mydomain.com" />
          </conditions>
          <action type="Redirect" url="http://www.mydomain.com/{R:0}" />
        </rule>
      </rules>
    </rewrite>
 </system.webServer>

OTHER TIPS

Turn the build action of your web.config to None. That will prevent the file from being deployed each time you publish.

Edit

For inserting entire sections into a web.config from the web.release.config, you need the xdt:Transform="Insert" added like so:

<system.webServer xdt:Transform="Insert">
        <rewrite>
          <rules>
            <rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true">
              <match url="*" />
              <conditions>
                <add input="{HTTP_HOST}" pattern="mydomain.com" />
              </conditions>
              <action type="Redirect" url="http://www.mydomain.com/{R:0}" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top