-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi all,
I have an application with user login, when the user log out its easy to clean the session but the user not always use the log out, sometimes just close the page or pages. One session has one or more desktops and when the user close or refresh one page DesktopCleanup is triggered, I use an Integer to know how many desktops the user have on the session so when the user close all desktops I could kill Session, the problem is that when only 1 desktop left if the user refresh this I don't know if the user closed o refresh the page, is there any way to know if DesktopCleanup is triggered by Close or Refresh page?
Thanks.
technically there is no difference between closing a browser(tab), navigating away for reloading the page. Each of these operation is triggered by the same "onBeforeUnloading"-event listener and will send the same "rmDesktop"-command to the server in order to destroy the desktop (including DesktopCleanup). So unfortunately i can't think of a solution from that angle.
At server side you could do something slightly different (maybe not 100% perfect but maybe good enough).
Once the number goes down to 0 (last desktop destroyed) you can - instead of invalidating the session - set a short maxInactive interval (e.g. 10 seconds) so that the session will not invalidate immediately. If the user just refreshed the page the next request will (hopefully) arrive in time, to reuse the previous session. In your DesktopInit listener you can then again count up to 1 and restore the original maxInactiveInterval to extend the session.
If the user really left the page the session will then timeout after 10 seconds and trigger a SessionCleanup Listener where you can perform your logout/cleanup tasks.
Does this make sense/help with your scenario? As said it's not perfect but a reasonably short period should be sufficient to allow page refresh - while timing out reasonably early otherwise.
Robert
Asked: 2018-02-28 01:13:36 +0800
Seen: 13 times
Last updated: Mar 02 '18