ASP.NET - How to kill session on any browser close button click(not on F5,Ctrl+F5 and pageload).

Asked By ram mahajan on 03-Jul-14 01:32 AM

Hi robbe/All,

I have seen this article “Prevent Multiple Logins Using the Cache in ASP.NET” on your site “”.

Here you are using cache functionality to achieve above requirement. I need following functionality

  1. Only one user is allowed to login with one username and password at a time on any machine.
  2. I need to clear/kill session on browser close only(not on page refresh or timer refresh).

From your code I understood that cache will clear after given session time.

But I need to clear it when user clicks on close button of any browser.

I have seen many solutions on internet but all are not working well.

Some are clearing session on browser close but along this session is cleared on page refresh(i.e.F5,Ctrl+F5 and reload page icon in browser.)

Will you please guide me how to achieve this? Its really urgent.

Kind regards
Ram Mahajan
Robbe Morris replied to ram mahajan on 03-Jul-14 07:44 AM
You cannot reliably trap the closure of the browser session ending or closing down.  You'll get most but not all.  That's why I used the techniques in that article.  You'll need to have a way to clear our sessions that did not get closed properly.
ram mahajan replied to Robbe Morris on 03-Jul-14 10:07 AM
I am asking about only the technique to clear session that is not closed properly. Is that your code clears session on browser close or not? I am stucked here.  Not getting anything.  Any help will be appreciated.