asp.net mvc 会话超时
如何为 ASP.NET MVC 应用程序实现会话超时功能?我希望一旦检测到给定时间段内不活动,用户就会自动注销。
我可以实现 ActionFilterAttribute 并应用于每个方法,但这不会自动注销用户。仅当用户尝试调用该操作的方法时,它才会注销。
谢谢。
How to implement a session timeout feature for an asp.net mvc application? I want user to be automatically signed out once inactivity is detected for a give time period.
I can implement an ActionFilterAttribute and apply to each method but that would not automatically sign out the user. It will sign out only when user tried to invoke the method for that action.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该能够从 web.config 进行管理:
我不是 MVC 专家,但在 ASP.NET 上推出的这种行为的改变并不是我所期望的。
也可以使用 IIS 管理应用程序进行配置;不确定您使用的是哪个版本的 IIS,但这篇 Technet 文章介绍了 即使在旧版本(IIS7 之前)中,也应该很容易理解。请注意,此方法在幕后仍然管理 web.config 文件中的设置,因此如果这是版本控制的,我不建议以这种方式更改它。
You ought to be able to manage this from the web.config:
I'm no MVC expert, but a change in this behaviour rolled out across ASP.NET is not something I'd expect.
This can also be configured using the IIS management application; not certain which version of IIS you're using, but this Technet article describes what should be easy to follow even in older (pre-IIS7) versions. Note that behind the scenes this method still manages the settings within the web.config file, so if this is version-controlled I wouldn't recommend changing it in this manner.
之所以如此,是因为会话是在服务器端维护的。如果你希望用户浏览器中的空闲页面自动注销,你必须为其编写一些 JavaScript。您可以使用ajax请求来检查会话是否过期,并根据结果将用户重定向到索引(登录或任何其他不需要身份验证的页面)
That is so because session is maintained on server side. if u want that an idle page in user's browser be signed out automatically, you have to write some javascript for it. you can use ajax request to check if session is expired or not and depending upon the result you can redirect the user to index (login or any other page that does not require authentication)