2013-10-23 69 views
2

我有一個問題,有人發佈了我的asp.net mvc3網站的網址,其中包含%3D而不是等號後的id參數如下:http://ultimategamedb.com/Article/Article?id%3D398210c1-529e-4909-9793-a11b8a832dcc。我嘗試了各種重寫規則,但似乎無法正確重寫爲:http://ultimategamedb.com/Article/Article?id=398210c1-529e-4909-9793-a11b8a832dcc。這是一個問題,因爲帶有%3D的網址會給出404錯誤。如果可能的話,我想創建一個規則,用%編碼將任何URL重寫爲正確的解碼值。如果這是不可能的,我只想知道如何重寫我的文章網址,以確保%3D永遠不會再次顯示文章網址中的等號。IIS URL重寫URL鏈接與%3D

任何人都可以向我解釋我將如何去創建這些重寫規則?提前致謝!

回答

2

您有幾種選擇:

  1. 寫自己的供應商將取代%3D=

    參考:http://www.iis.net/learn/extensions/url-rewrite-module/developing-a-custom-rewrite-provider-for-url-rewrite-module

  2. Application_BeginRequest,更換您的路徑:

    protected void Application_BeginRequest(object sender, EventArgs e) 
    { 
        string path = HttpContext.Current.Request.Url.PathAndQuery; 
    
        // Search for %3D and replace. 
        path = path.Replace("%3D","="); 
    
        HttpContext.Current.RewritePath(path); 
    }