问题
I'm new to URL routing.
Case 1: I can implement URL Routing for URL:/content/category.aspx
mapped to /Reservation
Case 2: I'm not quite sure how to handle the query string values.
For example:
URL:/content/category.aspx?SID=5&CID=191
I want this to map to: /Reservation
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 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
-In web config
</modules>
回答1:
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
来源:https://stackoverflow.com/questions/999481/passing-querystring-ids-url-routing-using-namespace-system-web-routing