Session_End does not fire when user closes browser

Discussion in 'ASP .Net' started by Keith-Earl, Nov 15, 2004.

  1. Keith-Earl

    Keith-Earl Guest

    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
     
    Keith-Earl, Nov 15, 2004
    #1
    1. Advertising

  2. Keith-Earl

    John M Deal Guest

    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

    Keith-Earl wrote:
    > 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
    >
    >
     
    John M Deal, Nov 15, 2004
    #2
    1. Advertising

  3. Keith-Earl

    Patrice Guest

    No. It fires when the session ends (by default 20mn later).

    Patrice

    --

    "Keith-Earl" <> a écrit dans le message
    de news:%...
    > 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
    >
    >
     
    Patrice, Nov 15, 2004
    #3
  4. Keith-Earl

    Curt_C [MVP] Guest

    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?

    --
    Curt Christianson
    Owner/Lead Developer, DF-Software
    Site: http://www.Darkfalz.com
    Blog: http://blog.Darkfalz.com


    "Keith-Earl" <> wrote in message
    news:%...
    >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
    >
     
    Curt_C [MVP], Nov 15, 2004
    #4
  5. "Keith-Earl" wrote:

    > 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
    >
    >
    >
     
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN, Nov 15, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. feng
    Replies:
    1
    Views:
    495
    Cowboy \(Gregory A. Beamer\)
    Dec 3, 2003
  2. srivalli c via DotNetMonster.com

    does Session_End event fire when the worker process recycles?

    srivalli c via DotNetMonster.com, Jun 22, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    571
  3. Annie
    Replies:
    6
    Views:
    4,038
    JIMCO Software
    Sep 14, 2005
  4. =?Utf-8?B?T2xkUHJvZ3JhbW1lcg==?=

    Session_End Event does not Fire.

    =?Utf-8?B?T2xkUHJvZ3JhbW1lcg==?=, Sep 19, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    3,118
    S. Justin Gengo
    Sep 22, 2005
  5. Rafael Chemtob

    session not being killed after user closes browser

    Rafael Chemtob, Feb 11, 2004, in forum: ASP General
    Replies:
    4
    Views:
    390
    Vilmar Brazão de Oliveira
    Feb 12, 2004
Loading...

Share This Page