2009-06-16 85 views
0

我是新來的URL路由。傳遞querystring ID使用名稱空間的URL路由system.web.Routing

案例一:我可以實現URL路由爲URL:/content/category.aspx映射到/Reservation

案例2:我不太知道如何處理的查詢字符串值。

例如:

URL:/content/category.aspx?SID=5&CID=191 

我想這映射到:案例1的書面/Reservation

代碼:

的Global.asa

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) 
    RegisterRoutes(RouteTable.Routes) 
End Sub 

Shared Sub RegisterRoutes(ByVal routes As RouteCollection) 
    Dim urlPattern As String 
    Dim Reservation As Route 
    urlPattern = "Reservation/" 
    Reservation = New Route(urlPattern, New JRouteHandler("~/content/category.aspx")) 
    RouteTable.Routes.Add("Reservation", New Route("Reservation", New JRouteHandler  ("~/content/category.aspx"))) 
End Sub 

的Http處理器

Public Sub New(ByVal virtualPath As String) 
    _virtualPath = virtualPath 
End Sub 

Public Function GetHttpHandler(ByVal requestContext As RequestContext) As IHttpHandler Implements IRouteHandler.GetHttpHandler 
    If (Not UrlAuthorizationModule.CheckUrlAccessForPrincipal(_virtualPath, requestContext.HttpContext.User, requestContext.HttpContext.Request.HttpMethod)) Then 
     requestContext.HttpContext.Response.StatusCode = CInt(Fix(HttpStatusCode.Unauthorized)) 
     requestContext.HttpContext.Response.End() 
    End If 

    Dim display = TryCast(BuildManager.CreateInstanceFromVirtualPath(_virtualPath, GetType(Page)), name) 

    display.pageName = TryCast(requestContext.RouteData.Values("name"), String) 
    Return display 
End Function 

Public Interface name 
    Inherits IHttpHandler 
    Property pageName() As String 

End Interface 

- 在Web配置

</modules> 

+0

@OP,請編輯並重寫有關web配置問題的最後部分 - 完全不清楚您的問題是什麼。 – 2009-06-16 03:52:44

+0

我用Intelligencia.UrlRewriter.dll來重寫URL.If我通過ASP.NET開發服務器運行應用程序,我可以實現我的路由(http:localhost:1130/reserve/home)如果我通過IIS 5.1運行應用程序,我mgetting HTTP 404文件未找到錯誤。 – jyoti 2009-06-30 04:00:20

回答

0

你不能做到這一點,你正在做的方式。我們已經在這個免費的第三方DLL的幫助下實現了URL重寫,您可以藉助此工具實現您想要的內容。它也可以處理查詢字符串。我們所做的是將DLL添加到我們的解決方案中,並在web.config中爲URL映射編寫規則。請試試這個,如果你需要進一步的幫助,請告訴我。
http://www.urlrewriting.net/149/en/home.html

相關問題