简体   繁体   English

asp.net mvc会话超时

[英]asp.net mvc session timeout

How to implement a session timeout feature for an asp.net mvc application? 如何为asp.net mvc应用程序实现会话超时功能? 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. 我可以实现一个ActionFilterAttribute并应用于每个方法但不会自动注销用户。 It will sign out only when user tried to invoke the method for that action. 仅当用户尝试调用该操作的方法时,它才会签出。

Thanks. 谢谢。

You ought to be able to manage this from the web.config: 你应该能够从web.config管理这个:

<system.web>
    <sessionState timeout="x"/> 
    ...
</system.web>

I'm no MVC expert, but a change in this behaviour rolled out across ASP.NET is not something I'd expect. 我不是MVC专家,但是在ASP.NET中推出的这种行为的改变并不是我所期望的。

This can also be configured using the IIS management application; 这也可以使用IIS管理应用程序进行配置; 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. 不确定您使用的是哪个版本的IIS,但是这篇Technet文章描述了即使在较旧的(IIS7之前版​​本)版本中应该易于理解的内容。 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. 请注意,在幕后,此方法仍然管理web.config文件中的设置,因此如果这是版本控制的,我建议不要以这种方式更改它。

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. 如果你想要自动注销用户浏览器中的空闲页面,你必须为它编写一些javascript。 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) 您可以使用ajax请求来检查会话是否过期,并根据结果将用户重定向到索引(登录或任何其他不需要身份验证的页面)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM