如何在Global.asax中检测请求是否为回调? [英] How do I detect if a request is a callback in the Global.asax?

查看:79
本文介绍了如何在Global.asax中检测请求是否为回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

推荐答案

这可能对您有帮助:
http://msdn.microsoft.com/en-us/magazine/cc163941.aspx

搜索单词__CALLBACKID:

This may help you: http://msdn.microsoft.com/en-us/magazine/cc163941.aspx
Search for the word __CALLBACKID:


要确定回调模式,请使用ASP.NET运行时在Request集合中查找__CALLBACKID条目。如果找到了这样的条目,则运行时将得出正在进行回调调用的结论。

我们需要这样做从无法访问Page.xxxx对象的app_code文件中。这是我最终使用的代码:

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

也许不是最漂亮的解决方案,但它确实可以做到。我们使用Array.IndexOf已有一段时间,但似乎有时form参数作为小写参数返回(不确定原因或方式),而Array.IndexOf是区分大小写的搜索。

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.

请小心寻找此类__XXXX请求密钥。我记得在某处读过,捷径这些元素不是一个好主意,因为它们的名称可能会在将来的.net版本中更改。请记住这一点!

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!

这篇关于如何在Global.asax中检测请求是否为回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆