2012-03-31 73 views
0

我正在使用Intelligencia UrlRewriter URL重寫,唯一的問題是尾隨斜線。 我在web.config在URL Rewrting ASP.NET跟蹤斜槓問題

<rewrite url="~/moviesarchive/(.+)" to="~/MoviesArchive.aspx?p=$1" /> 

這條規則它的工作原理,當我使用http://localhost/site/moviesarchive/1,我處理的情況時p參數爲空或空,http://localhost/site/MoviesArchive.aspx,但是當我刪除斜線,http://localhost/site/moviesarchive或我使用http://localhost/site/moviesarchive/,我得到HTTP Error 404.0 - Not Found錯誤。我該如何解決它?

回答

0

在你的頁面加載事件中添加:

Dim rawUrl As String = HttpContext.Current.ApplicationInstance.Request.RawUrl 
    If Not rawUrl.EndsWith("/") Then 
     HttpContext.Current.ApplicationInstance.Response.RedirectPermanent(String.Format("~{0}/", rawUrl)) 
    End If