[英]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.