【问题标题】:Web Deploy deleting IIS website custom configurationWeb Deploy 删除 IIS 网站自定义配置
【发布时间】:2014-04-08 20:17:24
【问题描述】:

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

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

问题是每次我部署一个新版本的站点时,这个额外的配置都会被删除。

这是预期的行为还是有什么问题?如何在每次部署时保留这些自定义设置?

更新

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

这是我在Web.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>

【问题讨论】:

  • 这些更改是否已放入已部署的 web.config 中?如果您检查本地 web.config 和已部署(在进行更改之后)之间的差异,文件之间是否存在差异?
  • @NoLifeKing 不,正如我所说,更改是通过 IIS 管理器进行的,而不是 web.config。我需要通过 web.config 来制作它们吗?
  • 在 IIS 管理器中所做的更改会使用新值更改已部署的 web.config。当然,改变的东西也有例外,并不是所有的东西都放到web.config中。

标签: asp.net asp.net-mvc iis iis-7.5 webdeploy


【解决方案1】:

将 web.config 的构建操作设置为无。这将阻止文件在您每次发布时被部署。

编辑

要将整个部分从 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>

【讨论】:

  • 但我确实想部署 web.config 文件(我可能在那里添加了一些东西)。所以看来唯一的办法就是直接在web.config上添加自定义配置吧?
  • 发布将始终覆盖目标 web.config。没有合并两个文件。您必须在本地 web.config(主要或 .Release.config)的某处进行更改,以便发布使用正确的服务器设置推送所有更改。
  • 到现在为止。我会将这些配置放在 Web.Release.config 中。谢谢。
  • 对不起乔希,你能再检查一下我的答案吗?我已经更新了它。我想我缺少一些 XDT 转换规则...
  • 响应不够快。很高兴你明白了。
【解决方案2】:

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

我将此添加到 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    • 2016-03-22
    • 2013-05-02
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多