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.
Dim lng As String = HttpContext.Current.Request.RequestContext.RouteData.Values("locale")
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.
精彩评论