我是网址路由的新手。
案例1:我可以为映射到URL:/content/category.aspx
/Reservation
实施网址路由
案例2:我不太确定如何处理查询字符串值。
例如:
URL:/content/category.aspx?SID=5&CID=191
我想将其映射到:/Reservation
为案例1编写的代码:
的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 Handler
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>
答案 0 :(得分:0)
你无法按照自己的方式去做。我们已经在这个免费的第三方DLL的帮助下实现了URL重写,您可以借助此工具实现您想要的功能。它也可以处理查询字符串。我们所做的是将DLL添加到我们的解决方案中,并在web.config中编写规则以进行URL映射。请尝试这个,如果您需要进一步的帮助,请告诉我。
http://www.urlrewriting.net/149/en/home.html