简体   繁体   English

如何在用户关闭选项卡/浏览器时注销grails?

[英]How to logout in grails when user closes the tab/browser?

我正在使用grails 1.3.5,当我们关闭浏览器或打开我的应用程序的所有选项卡时,我需要从我的应用程序中自动注销用户。

While there is no particularly reliable way to do this (in any web framework, not just Grails), there are some rather hacky ways you can get close to this, though there are some massive tradeoffs. 虽然没有特别可靠的方法来做到这一点(在任何网络框架中,不仅仅是Grails),但是有一些相当黑客的方法可以接近这一点,尽管存在一些巨大的权衡。

In general, since you have a default session timeout, the user will be logged out (in general) when their session expires due to not receiving a request associated with their session. 通常,由于您具有默认会话超时,因此用户将在其会话到期时因未收到与其会话关联的请求而退出(通常)。 This behavior can be changed depending on your security environment, but we'll assume you are using (sensible) defaults. 可以根据您的安全环境更改此行为,但我们假设您使用(合理的)默认值。

This session expiration logout can be ab used to mimic logging them out when they have no windows/tabs with your application open in them. 这届期满注销可以 从头 来模仿登录他们时,他们没有窗户/卡口与您的应用程序在他们开放。 To do this, you could have a small piece of JavaScript that continually "pings" your server at whatever interval you specify to keep the session "alive" and keep them logged in. How tight you set these pings is a tradeoff between the load on your server and the window of time where they could close their browser and re-open it and still stay logged in. 要做到这一点,你可以拥有一小段JavaScript,它会在你指定的任何时间间隔内“ping”你的服务器,以保持会话“活着”并让他们保持登录状态。你设置这些ping的紧张程度是负载之间的权衡。您的服务器以及他们可以关闭浏览器并重新打开它并仍然保持登录状态的时间窗口。

Like I said, this is very hacky, but it's functional. 就像我说的,这是非常 hacky,但它是功能性的。

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

相关问题 当用户关闭基于django2.0构建的网站上的选项卡或浏览器时,如何强制注销用户 - How to forcefully log out a user when user closes tab or browser on website built on django2.0 关闭浏览器选项卡时如何调用nodejs注销api? - How to call a nodejs logout api when close the browser tab? 如何在客户端关闭浏览器选项卡或window时向Nodejs后端服务器发送请求? - How to send a request to Nodejs backend server when the client closes the browser tab or window? 单击返回浏览器并且用户已经注销时如何拒绝用户访问 - How to deny user access when back in browser is clicked and user have already logout 在 laravel 5.6 中重置密码时从所有浏览器注销用户 - Logout user from all browser when password is reset in laravel 5.6 当密码更改时,从所有浏览器注销用户 - Logout User From all Browser When Password is changed 关闭浏览器后注销用户 - Logout user after closing the browser 如何在ASP.NET MVC中关闭浏览器或选项卡时将用户注销? - How do I log a user out when they close their browser or tab in ASP.NET MVC? 我如何知道用户何时通过关闭 php 中的浏览器选项卡注销? - How can I know when the user logged out by closing the browser tab in php? JSON Web Token过期时如何自动注销用户? - How to Auto logout the user when JSON Web Token Expires?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM