views:

1086

answers:

1

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>

A: 

You can't do in this way, like you are doing. we have implement URL Re-Writing with the helping of this free third party DLL, you can acheive what you want with the help of this. you can handle query string as well. what we did add ddl into our solution and write Rule in web.config for URL mapping. Plz try this, If you need further help. let me know
http://www.urlrewriting.net/149/en/home.html

Muhammad Akhtar
URL Routing using namespace system.web.Routing : how to Pass querystring values
jyoti
Muhammad Akhtar
used dll and working fine.if try to run web application using IIS i m getting error HTTP 404 file not found.
jyoti
this error occur when file not exist physically...Check the path from URL and make sure you have that file in that location....
Muhammad Akhtar
When i run application through VS 2008 working fine.But when i run same using IIS it is giving this erro
jyoti
there must be path problem, plz check ur URL. I can't guess here ur problem. how can i check ur problem... ???
Muhammad Akhtar