在 ASP.net 中不活动 20 分钟后注销(向数据库写入一行)
我想找到一个教程,展示如何在一段时间不活动后注销。
通过注销,我的意思是向我的 SQL 数据库写入一行。数据库表设计有一个名为 user_status 的列。当用户登录时,ASP 会将名为“已登录”的行写入数据库表中。我想找到一种自动机制,在一定的不活动状态后将行写入数据库
I'd like to find a tutorial that shows how to logout after a certain period of inactivity.
By logging out, i mean writing a Row to my SQL database. The database table was designed with a column called user_status. When a user logs in, ASP writes a row called "logged in" into the database table. I want to find an automatic mechanism that writes a Row to the database after a certain pd of inactivity
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ASP.NET 不提供任何可以在不活动后运行的事件。您也许能够与会话结束事件(如果我没记错的话,Session_end)联系起来,但我知道该事件不是很可靠。
我能想到的最简单的方法是在表中跟踪用户上次活动时间。然后更新每个操作的最后活动时间(显示和回发)。另设一个例程,每分钟运行一次,扫描表中 20 分钟不活动的人员。找到这些人后,重置他们的 user_status 条目。
ASP.NET doesn't provide any event that can run after inactivity. You might be able to tie into the session ending event (Session_end if I remember correctly) but I know that event isn't very reliable.
The easiest way I can think of to do this will be to track the users last activity time in a table. Then update the last activity time on every action (both display and post backs). Have another routine that runs every minute scanning the table for people who have been inactive for 20 minutes. When those people are found, reset their user_status entry.
您可以在应用程序 (Global.asax) 的 SessionEnd 事件中执行类似的操作。
但是,仅当会话状态模式为 InProc 时才会引发 SessionEnd。
You could possibly do something like that in the SessionEnd event of the Application (Global.asax).
However, the SessionEnd is only raised if the sessionstate mode is InProc.