Session_End does not fire when user closes browser

K

Keith-Earl

I thought for sure Session End would fire when the user closes his browser,
but no luck. The only way I can get the event to fire is to run a
Session.Abandon, but is that really practicle? When a user is down they
will probably close out the browser or navigate somewhere else.

I want to keep a total count of users in an Application state variable but I
cannot count on the decrement code to run. What can I do to keep up with
Total Users in my app?

Many thanks,

Keith
 
J

John M Deal

Session End fires when a session is abandoned or times out (default of
20 minutes). This is because the server has no way of knowing when the
browser has closed (stateless and all that jazz).

The drawback to all this is it makes getting an accurate count quite
difficult as you can't force a user to hit a logout button, you can't
reliably catch the browser closing event, and if you shorten the session
timeout too far you may end up with upset users whose session values got
cleared while they wrote up a sticky note to pickup the kids from school.

Also remember that each unique instance of a browser gets its own
session, so one user could open two instances of the website in two
browsers on their desktop (past experience says this happens more than
one might think). When this happens you loose some of the accuracy of
your count. If you are willing to go with the idea that the best you are
going to get is "close enough" then I'd say keep going with what you
have and accept that the numbers you are seeing are an approximation
over the life of a session timeout. Oh, and if you use some form of
logon you can get this a bit more accurate by keeping count of only the
unique logons within the timeout range.

Hope that helps in some manner.

Have A Better One!

John M Deal, MCP
Necessity Software
 
C

Curt_C [MVP]

This is actually kind of by design. WWW is a stateless system. Users aren't
connected. They connect, get the info, disconnect. All these "counts" are
false in reality. Now, that said, the Session End will fire when they
timeout so you will still get a decent count but it may take a while for the
timeout to occur. A "logout" button will help as well, with the
Session.Abandon as you indicated but there is no 100% way to get the count
you are after because that number doesn't really exist in the first place...
Make sense?
 
G

Guest

Keith-Earl said:
I thought for sure Session End would fire when the user closes his browser,
but no luck. The only way I can get the event to fire is to run a
Session.Abandon, but is that really practicle? When a user is down they
will probably close out the browser or navigate somewhere else.

I want to keep a total count of users in an Application state variable but I
cannot count on the decrement code to run. What can I do to keep up with
Total Users in my app?

Many thanks,

Keith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top