Member logout - force member logout if they close the browser
I have a member section. Once a user logs in they have access to protected content. If the user closes the browser before clicking on the logout button, can I force a user to be logged out? I do have a timeout for the overall website set in the web.config but would like a member account to be immediately logged out if they close the browser.
This is a tricky requirement. I can think of a few ways of doing this but they come with pros and cons - I'd be interested to hear with what you end up doing.
Try to detect the browser close event, and call an api to log out.
https://stackoverflow.com/questions/3888902/detect-browser-or-tab-closing -
PROS: probably the easiest to implement
CONS: depends on browser support - no idea if it will work with mobile browsers etc - I think this will be unreliable.
Reduce your member session timeout and somehow extend this on each page load (e.g. if a new page isn't hit in 5 minutes then assume the session is invalid.
PROS: Multiple tabs will work.
CONS: This won't be on close but will might be "close enough"?
On login store some kind of unique guid to the local storage in the browser and against the user session. If these don’t agree bounce the user to the login page and kill their session on the next hit.
PROS: Will work for what you need
CONS: Duplicate tabs will probably cause issues here – this will need testing. It will only work on HTML5 browsers.
I think you probably want to have a go with option 3.
Member logout - force member logout if they close the browser
I have a member section. Once a user logs in they have access to protected content. If the user closes the browser before clicking on the logout button, can I force a user to be logged out? I do have a timeout for the overall website set in the web.config but would like a member account to be immediately logged out if they close the browser.
Hi,
This is a tricky requirement. I can think of a few ways of doing this but they come with pros and cons - I'd be interested to hear with what you end up doing.
I think you probably want to have a go with option 3.
HTH
Steve
We ended up creating a surfacecontroller that handled it. Then just used the standard login form that used this surfacecontroller.
Thanks,
is working on a reply...