Web Deploy deleting IIS website custom configuration
Asked Answered
M

2

7

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>
Marksman answered 8/4, 2014 at 20:17 Comment(3)
Are these changes put into the web.config that is deployed? If you check the difference between your local web.config and the deployed (after the changes have been made), is there something that differs between the files?Karim
@Karim No, as I said, the changes were made through IIS manager, not web.config. Do I need to make them through web.config?Marksman
Changes made in the IIS Manager changes the deployed web.config with the new values. Of course, there are exceptions to what is changed, not everything is put into the web.config.Karim
M
0

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>
Marksman answered 8/4, 2014 at 20:52 Comment(0)
A
4

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>
Accordion answered 8/4, 2014 at 20:24 Comment(5)
But I do want to deploy the web.config file (I might have added something there). So it seems the only way is to add the custom configuration directly on the web.config right?Marksman
Publish will always overwrite the destination web.config. There is no merging the two files. You'll have to have to have the changes somewhere on a local web.config (the primary or the .Release.config) in order for the publish to push all changes with the correct server settings.Accordion
Good to now. I'll put those configs in the Web.Release.config. Thanks.Marksman
Sorry Josh, can you check my answer again? I've updated it. I think I'm missing some XDT Transform rule...Marksman
Couldn't respond quick enough. Glad you figured it out.Accordion
M
0

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>
Marksman answered 8/4, 2014 at 20:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.