问题描述
我是 URL 路由的新手.
I'm new to URL routing.
案例 1:我可以为映射到 /Reservation
Case 1: I can implement URL Routing for URL:/content/category.aspx
mapped to /Reservation
案例 2:我不太确定如何处理查询字符串值.
Case 2: I'm not quite sure how to handle the query string values.
例如:
URL:/content/category.aspx?SID=5&CID=191
我希望它映射到:/Reservation
为案例 1 编写的代码:
Code written for Case 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 处理程序
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>
推荐答案
你不能按照你的方式去做.我们在这个免费的第三方 DLL 的帮助下实现了 URL 重写,你可以在这个工具的帮助下实现你想要的.它也可以处理查询字符串.我们所做的是将 DLL 添加到我们的解决方案中,并在 web.config 中编写 URL 映射规则.请尝试此操作,如果您需要进一步的帮助,请告诉我.
http://www.urlrewriting.net/149/en/home.html
You can't do it the way you are doing. We have implemented URL Re-Writing with the help of this free third party DLL, you can achieve what you want with the help of this Tool. It can handle query strings as well. What we did was add the DLL into our solution and write rules in the web.config for URL mapping. Please try this and if you need further help let me know.
http://www.urlrewriting.net/149/en/home.html
这篇关于使用命名空间 system.web.Routing 传递查询字符串 Ids URL 路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!