ASP.NET路由。如何在通用处理程序中使用路由?

时间:2011-08-03 19:23:39

标签: asp.net vb.net ashx asp.net-routing generic-handler

我尝试在以下通用处理程序中使用ASP.Net,但我在Page.RouteData

时收到此错误
Reference to a non-shared member requires an object reference

我做错了什么?

<%@ 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

对于任何答案,请记住我是新手,我的舌头语言是VB.NET :) 提前谢谢。

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

请尝试以下操作。您必须检索路由表并从中读取。

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

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

有关路由的详细信息,请查看此linkmsdn