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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With