MVC 3 中如何处理会话超时
我遇到了频繁的会话超时问题。
我想编写一个可以在每个控制器上使用的通用过滤器,过滤器应重定向用户登录,并在登录后返回到用户发送最后一个请求的位置。
I am having issues with frequent Session Time Out.
I want to write a common filter that I could use on each controller, filter should redirect the user to login and after log in back to from where user sent the last request.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你可以尝试这样的事情:
You could try something like this:
这里的东西比我们看到的还要多。这是一个更完整的 OnActionExecuting,它使用上面已经讨论过的相同概念,但添加了更多内容。有关更多信息,请参阅内嵌注释。被调用的“InitializeSession”是一个自定义函数,它创建会话状态中运行站点所需的基本属性。 “AlertWarning”是用于显示警报的帮助程序。其他一切都是样板代码。
There's more here than meets the eye. Here's a more complete OnActionExecuting that uses the same concept already discussed above but adds a bit more. See inline comments for more info. The "InitializeSession" being called is a custom function which creates the basic attributes needed in Session State for running the site. "AlertWarning" is a Helper routine for displaying alerts. Everything else is boilerplate code.
您是否尝试过现有的授权过滤器?
Have you tried the existing Authorize filter?
如上所述..尝试这个
,然后在操作或控制器上应用这个过滤器
[SessionExpire]
as mentioned above .. try this
and then apply this filter over the action or controller
[SessionExpire]