OrElse
OrElse

Reputation: 10009

ASP.NET Routing. How can i use Routing in a Generic Handler?

I tried to use ASP.Net's in the following generic handler, but i get this error at Page.RouteData

Reference to a non-shared member requires an object reference

What i am doing wrong?

<%@ WebHandler Language="VB" Class="MainHandler" %>

Imports System
Imports System.Web
Imports System.Xml


    Public Class MainHandler : Implements IHttpHandler, System.Web.SessionState.IRequiresSessionState

        Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

            Dim lng As String = Page.RouteData.Values("locale")

        End Sub

        Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
            Get
                Return False
            End Get
        End Property

    End Class

For any answers, please keep in mind that i am a newbie, and my tongue language is VB.NET :) Thank you in advance.

Upvotes: 2

Views: 1299

Answers (2)

OrElse
OrElse

Reputation: 10009

 Dim lng As String = HttpContext.Current.Request.RequestContext.RouteData.Values("locale")

Upvotes: 2

coder net
coder net

Reputation: 3475

Try the following.You have to retrieve the route table and read from it.

Dim rd AS RouteData
rd = RouteTable.Routes.GetRouteData(new HttpContextWrapper(context))

Dim val AS String
val = rd.Values["locale"].ToString()

Take a look at this link and msdn for more details on routing.

Upvotes: 0

Related Questions