有关会话等的 httpmodule 问题
我在我的 asp.net Web 应用程序、iis7、.net 4.0 等中设置了 httpmodule。我有 2 个问题想要解决。
通过对 httpmodule 的调试,我发现该模块被 ScriptResource.axd 调用。它在被调用时运行。有什么办法可以阻止这种情况或“将其关闭”吗?我想让该模块为我的一些 httphandlers、.asmx 服务和 aspx 页面请求运行,但不希望产生脚本资源处理程序调用的开销。
其次,会话状态在 HttpModule 中是否可用?如果是,它在哪些事件中可用?
I have a httpmodule set up in my asp.net web application, iis7, .net 4.0 etc. I have 2 issues I would like to resolve.
From debugging of the httpmodule, I have found that the module gets called for ScriptResource.axd ie. it runs when this is called. Is there any way I can prevent this or "turn it off"? I want to have the module run for some of my httphandlers, .asmx services and aspx page requests but dont want the overhead of being called for scriptresource handlers.
Secondling, is session state available in HttpModules and if so, what events is it available at?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如前所述,
HttpModules
对应用程序中的所有请求启用,因此您唯一能做的就是检查HttpModule
中的传入 url,然后决定采取什么操作基于此。会话状态在
AcquireRequestState
事件期间加载,因此从HttpModule
检查会话状态的最早机会是PostAcquireRequestState
事件。会话状态在引发ReleaseRequestState
事件时保留,因此您对会话所做的任何更改都应在该点之前进行。因此,您可以在这些之间的HttpApplication 管道期间随时访问会话状态两个事件As already mentioned,
HttpModules
are enabled for all requests in an application so the only thing you can do is to inspect the incoming url in theHttpModule
and then decide what action to take based on that.Session state is loaded during the
AcquireRequestState
event so the earliest opportunity to inspect it from aHttpModule
is thePostAcquireRequestState
event. Session state is persisted at the point that theReleaseRequestState
event is raised, so any changes you make to the session should be made before that point. You can therefore access session state at any point during the HttpApplication pipeline between those two events