2013-03-16 30 views
2

工作我最近遷移的網站轉移到運行Windows Server 2008,然後在新服務器上的IIS 7的Response.Redirect停止了與IIS 7條重寫規則

我已經實現URL重寫規則的網頁被託管。這是一個例子。

   <rule name="RewriteUserFriendlyURL58" stopProcessing="true"> 
        <match url="^(shop)/(item)/([^/]+)/([^/]+)/([^/]+)/?$" /> 
        <conditions> 
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
        </conditions> 
        <action type="Rewrite" url="shopitem.aspx?{R:1}&amp;{R:2}&amp;id={R:3}&amp;cat={R:4}&amp;title={R:5}" /> 
       </rule> 

URL應該看起來像這樣。 http://www.website.com/shop/item/10/products/table/

除了當我點擊一個按鈕並運行此事件時,該頁面正常工作。

protected void btnAddToBasket_Click(object sender, EventArgs e) 
{ 
     Response.Redirect("~/shoppingbasket/"); 
} 

重定向的結果似乎是對自身重定向,然後將URL更改爲:http://www.website.com/shop/item/10/products/table/?shop&item&id=10&cat=products&title=table

任何人都可以點我在正確的方向?我已經做了一些搜索,我似乎無法找到任何東西。

+0

您是否嘗試過使用[失敗請求追蹤工具](http://www.iis.net/learn/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-規則)看看發生了什麼? – cheesemacfly 2013-03-16 17:41:29

回答

0

我使用以下教程here回答了此問題。

我把下面的代碼放在Page_Load事件的頂部。

if (!String.IsNullOrEmpty(Request.ServerVariables["HTTP_X_ORIGINAL_URL"])) 
{ 
    Form.Action = Request.ServerVariables["HTTP_X_ORIGINAL_URL"]; 
} 

該頁面現在按預期工作。

0

這看起來實際上是「拍攝,我錯過了!」我們都有的問題類型:)。

<action type="Rewrite" url="shopitem.aspx?{R:1}&amp;{R:2}&amp;id={R:3}&amp;cat={R:4}&amp;title={R:5}" /> 

您正在調用Rewrite。將其更改爲重定向,我相信它會按照您的預期執行。

值得注意的是,在事件中使用重定向和聯合重寫可能會在IIS中發生衝突。你可能想要選擇其中一個。