Application_AuthenticateRequest命中所有请求,包括图像和js文件
在我的 MVC3 应用程序中,我使用 Application_AuthenticateRequest 创建自定义用户上下文并创建会话。但是,我注意到每个页面请求的每个文件(包括图像、js、css 等)都会触发此
方法。这是执行我想做的事情的正确方法吗,还是我应该在其他地方执行此操作(即动作过滤器)?或者,这是正确的地方吗?我只需要进行一些检查和/或配置,以确保此方法(或我的代码块)仅针对页面请求而不是针对静态文件的请求执行?
我搜索了一段时间试图找到答案,并找到了一个特定于 IIS7 的答案,但这种情况发生在我的 WinXP 上的 ASP.NET 开发服务器(调试)上。除此之外,我找不到太多东西,这让我觉得我可能在某些事情上偏离了方向,可能忽略了一些简单的事情。
提前致谢。
In my MVC3 application, I'm using Application_AuthenticateRequest to create my custom user context and create the session. However, I notice that this is getting fired for every file per page request, including images, js, css, etc.
Is this the right method to do what I'm trying to do, or should I be doing this somewhere else (i.e. action filter)? Or, is this the right place, I just need to put some checks and/or configuration to ensure this method (or my block of code) is just executed for page requests instead of requests for static files?
I searched for a while trying to find the answer, and found one specific to IIS7, but this is happening for me on my ASP.NET dev server (debugging) on WinXP. Other than that, I couldn't find much, which leads me to think I may be way off on something here, possibly overlooking something simple.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Jerad,
您是正确的,您最好创建一个操作过滤器来处理您的用户上下文。您可以在需要用户上下文的地方装饰这些控制器。
这是比使用代码来调查请求更好的解决方案,这样您就可以忽略特定请求。
辅导员本
Jerad,
You are correct that you would be better off creating an action filter to handle your user context. You can decorate those controllers where the user context is required.
This is a better solution than using code to investigate the request, just so you can ignore particular requests.
counsellorben