如何检测请求是否是 Global.asax 中的回调?

发布于 2024-07-26 20:54:20 字数 394 浏览 2 评论 0原文

我需要找到一种方法来检测调用 Application_BeginRequest 方法时请求是否为回调。

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)<br />
    Dim _isCallBack As Boolean = False

    ' Code to set _isCallBack is True or False Here

    If Not _isCallBack Then
        '... Some Code
    End If
End Sub

我需要知道用什么替换“[此处设置 _isCallBack 的代码为 True 或 False]”。

I need to find a way to detect if a request is a callback when the Application_BeginRequest method is called.

Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)<br />
    Dim _isCallBack As Boolean = False

    ' Code to set _isCallBack is True or False Here

    If Not _isCallBack Then
        '... Some Code
    End If
End Sub

I need to know what to replace "[Code to set _isCallBack is True or False Here]" with.

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

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

发布评论

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

评论(3

李白 2024-08-02 20:54:20

这可能会帮助您:
http://msdn.microsoft.com/en-us/magazine/cc163941。 ASPX

搜索单词 __CALLBACKID:

为了确定回调模式,ASP.NET 运行时在 Request 集合中查找 __CALLBACKID 条目。 如果找到这样的条目,运行时就会得出结论,正在执行回调调用。

我们需要在无法访问 Page.xxxx 对象的 app_code 文件中执行此操作。 这是我最终使用的代码:

If Not IsNothing(HttpContext.Current.Request("__CALLBACKID")) Then
    'The request is a callback
Else
    'The request is not a callback
End If

也许不是最漂亮的解决方案,但它可以完成工作。 我们使用 Array.IndexOf 一段时间,但似乎有时该表单参数会以小写参数返回(不知道为什么或如何),并且 Array.IndexOf 是区分大小写的搜索。

小心寻找这些类型的 __XXXX 请求键。 我记得在某处读到,“快捷”到这些元素并不是一个好主意,因为它们的名称可能会在 .net 的某些未来版本中发生更改。 要时刻铭记在心!

This may help you:
http://msdn.microsoft.com/en-us/magazine/cc163941.aspx

Search for the word __CALLBACKID:

To determine the callback mode, the ASP.NET runtime looks for a __CALLBACKID entry in the Request collection. If such an entry is found, the runtime concludes that a callback invocation is being made.

We needed to do this from within an app_code file where access to the Page.xxxx objects was not available. This is the code I ended up using:

If Not IsNothing(HttpContext.Current.Request("__CALLBACKID")) Then
    'The request is a callback
Else
    'The request is not a callback
End If

Maybe not the prettiest solution, but it does the job. We were using Array.IndexOf for a while, but it seems that sometimes that form parameter arrives back as lowercase parameter (not sure why or how), and Array.IndexOf is a case sensitive search.

Be careful looking for these kinds of __XXXX request keys. I remember reading somewhere that it's not a good idea to "shortcut" to these elements since their names could change in some future version of .net. Just keep that in mind!

活泼老夫 2024-08-02 20:54:20

我需要类似的东西,并且根据 Dean L 的回答,我认为 .NET 本身必须知道要做什么。 使用 Reflector 查看 HttpResponse.Redirect 方法,您会看到如下代码:

Page handler = Context.Handler as Page;
if (handler != null && handler.IsCallback)
{
    //Code...
}

似乎在 Global.asax 中工作正常。

I needed something similar and, following on Dean L's answer, figured .NET itself must know what to do. Looking in the HttpResponse.Redirect method with Reflector, you see code like this:

Page handler = Context.Handler as Page;
if (handler != null && handler.IsCallback)
{
    //Code...
}

Seems to work fine in Global.asax.

月寒剑心 2024-08-02 20:54:20

取决于你的问题的上下文。 我看到您在标签中谈论 ASP.NET,使用 VB.NET。 你或许可以使用:

If Not Request.IsPostback Then
  ' Your code here
End If

Depends on the context of your question. I see you are talking about ASP.NET in the tags, using VB.NET. You can probably use:

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