2013-05-02 47 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