Detect moment when user closed session

  • Thread starter Thread starter NWx
  • Start date Start date
N

NWx

Hi,

I have the following question:

I have an app that uses user login/logout to identify users
When user logon, I register logon time in a session variable
When user logoff using the logout link, I also register logoff time and
update accordingly the logging history table.
However user can simply close the browser without logoff, so his session was
closed.
Is there any way to detect when this is happening, to allow me to get the
time and update logoff time field appropriate?

Thank you.
 
I don't believe what you are trying to do can be done accurately, with a
100% success rate (since it would require some client coding). If a client
wants to close their browser and not let the server know about it, they most
certainly can do that. You could try some crude javascript code to pop up a
window when the browser is closing which would execute some logoff code, but
with all the nice popup blockers these days...good luck.

Here's another option, and I'll leave it to you to implement if you want to.
For each page the user requests after the he is logged in, remember the
time, that time is the logout time, unless you get another request. You
could add a minute or so to it if you want to give the impression that the
user stayed there and looked at the page for a minute. Now look at the
session_end method in the global.asax file. Somehow set your logging
history table with this value when this method fires.

HTH,
--Michael
 
Thank you for your answers.
I thought about popup window, but you are right with the popup blockers.

I'll try your second suggestion.

Regards
 
Back
Top