Visual studio 2012 使用vs2012 web deployment web.config转换更新url重写规则

Visual studio 2012 使用vs2012 web deployment web.config转换更新url重写规则,visual-studio-2012,msdeploy,Visual Studio 2012,Msdeploy,我不知道如何使我的web.config部署转换适用于重写规则。我尝试了以下方法,但它忽略了它 <?xml version="1.0"?> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <system.webServer> <rewrite xdt:Transform="Replace"> <rules>

我不知道如何使我的web.config部署转换适用于重写规则。我尝试了以下方法,但它忽略了它

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">


 <system.webServer>
 <rewrite xdt:Transform="Replace">
  <rules>

    <rule name="Force HTTPS On Login/Register" stopProcessing="true">
      <match url="Account/Login(.*)|Register(.*)" ignoreCase="true" />
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
    </rule>


    <rule name="Force HTTPS Off" stopProcessing="true">
      <match url="((Account/Login(.*))|(Register(.*)))" negate="true" ignoreCase="true" />
      <conditions>
        <add input="{HTTPS}" pattern="^ON$" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="http://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
    </rule>


  </rules>
 </rewrite>
</system.webServer>

我使用SlowCheetah转换我的web.config进行生产。我最初尝试了您尝试的内容,但发现我必须添加一个空的

<rewrite>
  <rules />
</rewrite>

到基本web.config

然后写一个像这样的变换

<system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to HTTPS" stopProcessing="true" xdt:Transform="Insert">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="^OFF$" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
</system.webServer>

(这是一个重定向转换,但我认为应该应用相同的原则)


注意
xdt:Transform=“Insert”
将新节点插入基本配置文件中的骨架

按照建议工作。到目前为止,我还没有使用slowcheetah。我一直听说它,但只是讨厌不断增加我的依赖项。嗨,埃里克,你有没有见过一个问题,其中空规则给出了http 500.19错误?我的azure VM抛出该错误,但我的colo服务器(相同的操作系统)没有。不,我没有看到这种情况,尽管我没有使用azure。也许会针对Azure发布一个关于该错误的新问题?该错误意味着配置文件无效。您确定转换已正确应用于Azure VM吗?