1

我是 URL 路由的新手。

案例 1:我可以实现URL:/content/category.aspx映射到的 URL 路由/Reservation

案例 2:我不太确定如何处理查询字符串值。

例如:

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

我希望它映射到:/Reservation

为案例 1 编写的代码:

环球网

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

-在网络配置中

</modules>

4

1 回答 1

0

你不能按照你现在的方式去做。我们已经在这个免费的第三方 DLL 的帮助下实现了 URL 重写,您可以在这个工具的帮助下实现您想要的。它也可以处理查询字符串。我们所做的是将 DLL 添加到我们的解决方案中,并在 web.config 中为 URL 映射编写规则。请试试这个,如果您需要进一步的帮助,请告诉我。
http://www.urlrewriting.net/149/en/home.html

于 2009-06-16T09:51:24.460 回答