检查 Application_BeginRequest 上是否有 IsCallback
我有一个 Web 应用程序(.NET 3.5),它在 Global.asax 中包含以下代码:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
LinkLoader()
PathRewriter()
PathAppender()
End Sub
我希望调用其中的所有函数,除非它是 AJAX 回调。 因此,理想情况下我会将其更改为:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
If not Page.IsCallback then
LinkLoader()
PathRewriter()
PathAppender()
End If
End Sub
但此处无法访问页面对象。 所以,基本上我的问题是:
如何检查请求是否是 Application_BeginRequest 内的 AJAX 回调?
非常感谢您的任何反馈。
I have a web application (.NET 3.5) that has this code in Global.asax:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
LinkLoader()
PathRewriter()
PathAppender()
End Sub
I want all those functions inside to get called except for when it's an AJAX call back. So, ideally I would have it changed to:
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
If not Page.IsCallback then
LinkLoader()
PathRewriter()
PathAppender()
End If
End Sub
But there is not access to the page object here. So, basically my question is:
How do I check if the request is an AJAX call back inside Application_BeginRequest?
Thank you very much for any feedback.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
约翰,
谢谢你为我指明了正确的方向。 解决方案实际上是检查 Request.Form("__ASYNCPOST")。 如果它是回调,则将其设置为“true”。
非常感谢你的帮助!
John,
Thanks for pointing me in the right direction. The solution is actually to check for Request.Form("__ASYNCPOST"). It is set to "true" if it is a CallBack.
Thanks so much for the help!
您应该有权访问 HttpContext.Current.Handler 对象,您可以将其转换为 Page 对象并获取 Page.IsPostBack 或 Page.IsCallBack。 尽管为了安全地执行此操作,您需要首先测试它是一个 Page 对象并且不为 null:
You should have access to the HttpContext.Current.Handler object which you can cast to a Page object and get Page.IsPostBack or Page.IsCallBack. Although in order to do this safely you need to first test that it is a Page object and not null:
根据我的理解,IsCallback 所做的只是检查表单是否有一个名为 __CALLBACKARGUMENT 的 post 变量。 您可以自己在 Context.Request.Form 中检查表单,这应该会告诉您与 IsCallback 相同的信息。
From my understanding all IsCallback does is check if the form has a post variable named __CALLBACKARGUMENT. You could check the form yourself in Context.Request.Form and that should tell you the same thing as IsCallback.