在浏览器关闭时调用方法
当用户直接单击浏览器关闭 [X] 按钮时,我的应用程序遇到问题。浏览器可以是 IE、Chrome、Mozilla、Firefox 等。
我想做的: 1. 一旦用户点击浏览器的 [X] 按钮,就需要在数据库中将其状态设置为已注销,为此我们在母版页内的 Login.aspx 文件中有一个方法。 2.我们的应用程序中没有任何注销功能,
如果有人建议一个解决方案来调用将用户状态设置为从母版页注销的方法,我将不胜感激。
提前致谢。
I am facing an issue in my application when a user directly clicked on browser close [X] button. Browser can be IE, Chrome, Mozilla, Firefox and many more.
What I want to do:
1. as soon as user hits [X] button of browser, need to set their status as logged off in database for which we have a method in Login.aspx file which is within the master page.
2. We do not have any Logoff feature in the application
I will be thankful if anyone suggests a solution to call the method which sets the user status as logged off from master page.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于 http 连接和一般网络的性质,这是不可能的。只需设置一个超时(例如 10 分钟),之后用户就会自动注销。
This is not possible due to the nature of http connections and the web in general. Simply have a timeout (eg. 10 minutes) after which a user gets logged out automatically.
Javascript 有一个 onunload 函数,所以你可以这样做:
但是,这个方法和其他方法将是不可靠的(我不确定它在哪些特定实例中被触发),因为这将是一个安全问题,允许网站有权访问执行浏览器 onunload 上有很多功能。
最好的解决方案是让 cookie/会话自动超时,并教育用户在系统敏感时注销。
Javascript has an onunload function, so you could do:
However this, and other methods are going to be unreliable (I'm not sure in which specific instances it is fired) as it would be a security concern allowing websites to have access to perform many functions on browser onunload.
The best solution would be to have cookies/sessions automatically time out, and also to educate users to logout if the system is sensitive.
如果你使用 jQuery,你可以使用
但我必须同意 Tom Gullen 的观点 - 你的会话最终应该超时。
If you are using jQuery you could work with
But I have to agree with Tom Gullen here - your sessions should timeout eventually.