Web部署删除IIS网站自定义配置

时间:2022-09-03 21:29:38

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

我正在使用Web Deploy(来自VS2013)将ASP.NET MVC站点发布到IIS 7.5。

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

我通过IIS管理器添加了一些URL重写规则和自定义HTTP响应头。

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.

所以我理解我需要将这些更改放在web.config中。我正在尝试将它们放在Web.Release.config中,但它没有被添加到已部署的web.config中。我想我错过了一些XDT:转换规则。

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

这就是我在Web中发现的.Release.config(是的,发布配置文件正在使用此Release配置)。

<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>

2 个解决方案

#1


2  

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

将web.config的构建操作转为None。这将阻止每次发布时都部署文件。

Edit

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

要从web.release.config将整个部分插入到web.config中,需要添加xdt:Transform =“Insert”,如下所示:

<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>

#2


0  

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

好的,我知道我需要使用XDT:Transform在web.config中添加这个自定义配置。

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

我将此添加到Web.Release.config并且它有效:

<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>

#1


2  

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

将web.config的构建操作转为None。这将阻止每次发布时都部署文件。

Edit

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

要从web.release.config将整个部分插入到web.config中,需要添加xdt:Transform =“Insert”,如下所示:

<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>

#2


0  

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

好的,我知道我需要使用XDT:Transform在web.config中添加这个自定义配置。

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

我将此添加到Web.Release.config并且它有效:

<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>