2013-05-02 42 views
5

我无法弄清楚如何让我的web.config部署转换适用于重写规则。我试过以下,它忽略它。使用vs2012 web部署更新url重写规则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> 
+0

按照您的建议工作。到目前为止,我还没有使用slowcheetah。我一直听到它,但只是恨不断增加我的依赖。 – 2013-05-02 18:17:19

回答

6

我使用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"将新节点插入基本配置文件中的骨架<rules />

+0

嗨,埃里克,你有没有看到空规则给出一个http 500.19错误的问题?我的天蓝色虚拟机会引发这个错误,但我的colo服务器(相同的操作系统)不会。 – 2013-05-03 19:18:48

+0

不,我没有看到这种情况,尽管我没有使用Azure。也许发布有关Azure特定错误的新问题?该错误意味着配置文件无效。您确定该转换已正确应用于Azure VM吗? http://blogs.msdn.com/b/webtopics/archive/2010/03/08/troubleshooting-http-500-19-errors-in-iis-7.aspx – 2013-05-03 19:56:14