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

发布于 2024-11-27 21:55:40 字数 841 浏览 2 评论 0原文

我尝试在以下通用处理程序中使用 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 :) 先感谢您。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半﹌身腐败 2024-12-04 21:55:40
 Dim lng As String = HttpContext.Current.Request.RequestContext.RouteData.Values("locale")
 Dim lng As String = HttpContext.Current.Request.RequestContext.RouteData.Values("locale")
时光无声 2024-12-04 21:55:40

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

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

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

查看此链接msdn 了解有关路由的更多详细信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文