How can I make sure that Session_End is called when the user closes the browser?

Discussion in 'ASP .Net' started by Annie, Sep 13, 2005.

  1. Annie

    Annie Guest

    Hi guys,

    I just want to do some clean up in the Session_End at Global.aspx.

    However, if the user closes the browser window that event is not fired.

    how can I call explicity protected void Session_End(Object sender, EventArgs
    e)
    when the user closes the browser window?



    possible at all?



    TA
    Annie, Sep 13, 2005
    #1
    1. Advertising

  2. Annie wrote:
    > Hi guys,
    >
    > I just want to do some clean up in the Session_End at Global.aspx.
    >
    > However, if the user closes the browser window that event is not
    > fired.
    > how can I call explicity protected void Session_End(Object sender,
    > EventArgs e)
    > when the user closes the browser window?
    >


    Not possible. You're working with a connectionless architecture. The
    server has no knowledge of when the user closes their browser.

    --
    Jim Cheshire
    JIMCO Software
    http://www.jimcosoftware.com

    FrontPage add-ins for FrontPage 2000 - 2003
    JIMCO Software, Sep 13, 2005
    #2
    1. Advertising

  3. Annie

    Hans Kesting Guest

    Annie wrote:
    > Hi guys,
    >
    > I just want to do some clean up in the Session_End at Global.aspx.
    >
    > However, if the user closes the browser window that event is not
    > fired.
    > how can I call explicity protected void Session_End(Object sender,
    > EventArgs e)
    > when the user closes the browser window?
    >
    >
    >
    > possible at all?
    >
    >
    >
    > TA


    The session does not end when the user closes the browser, but (default)
    20 minutes after the last request to the site. (So if he was busy for 30 minutes
    reading a single page, the session would have ended).

    There is no (reliable) way to detect that the user has closed the browser,
    navigated away from the site, or lost his internet connection.

    Hans Kesting
    Hans Kesting, Sep 13, 2005
    #3
  4. Annie

    KMA Guest

    which is why ebanking software has a "log out" button, so it can call
    session abort.

    "Hans Kesting" <> wrote in message
    news:...
    > Annie wrote:
    > > Hi guys,
    > >
    > > I just want to do some clean up in the Session_End at Global.aspx.
    > >
    > > However, if the user closes the browser window that event is not
    > > fired.
    > > how can I call explicity protected void Session_End(Object sender,
    > > EventArgs e)
    > > when the user closes the browser window?
    > >
    > >
    > >
    > > possible at all?
    > >
    > >
    > >
    > > TA

    >
    > The session does not end when the user closes the browser, but (default)
    > 20 minutes after the last request to the site. (So if he was busy for 30

    minutes
    > reading a single page, the session would have ended).
    >
    > There is no (reliable) way to detect that the user has closed the browser,
    > navigated away from the site, or lost his internet connection.
    >
    > Hans Kesting
    >
    >
    KMA, Sep 13, 2005
    #4
  5. Annie

    Annie Guest

    wow gettting very interesting!
    How about catching it in client side using Javascript and something and
    passing it to server somehow?
    not possible at all?


    "Annie" <> wrote in message
    news:4326a30a$...
    > Hi guys,
    >
    > I just want to do some clean up in the Session_End at Global.aspx.
    >
    > However, if the user closes the browser window that event is not fired.
    >
    > how can I call explicity protected void Session_End(Object sender,
    > EventArgs e)
    > when the user closes the browser window?
    >
    >
    >
    > possible at all?
    >
    >
    >
    > TA
    >
    >
    Annie, Sep 14, 2005
    #5
  6. Annie wrote:
    > wow gettting very interesting!
    > How about catching it in client side using Javascript and something
    > and passing it to server somehow?
    > not possible at all?
    >


    Sessions use a sliding expiration. That means that as soon as you "pass it
    on to the server", you reset your Session expiration, thereby delaying the
    execution of Session_End, not expediting it.

    --
    Jim Cheshire
    JIMCO Software
    http://www.jimcosoftware.com

    FrontPage add-ins for FrontPage 2000 - 2003
    JIMCO Software, Sep 14, 2005
    #6
  7. Annie wrote:
    > wow gettting very interesting!
    > How about catching it in client side using Javascript and something
    > and passing it to server somehow?
    > not possible at all?
    >


    Hit Send too soon. :)

    Of course you could have your browser call a page that calls
    Session.Abandon, but you have to remember that there is no way to hook a
    client side event ONLY when the browser is closed. It would be impossible
    (as far as I can think right off this early in the AM) to detect the browser
    closing correctly.

    One more thing to add. Session_End is indeterminate. Even if you call
    Session.Abandon, you cannot guarantee when Session_End will get called.

    --
    Jim Cheshire
    JIMCO Software
    http://www.jimcosoftware.com

    FrontPage add-ins for FrontPage 2000 - 2003
    JIMCO Software, Sep 14, 2005
    #7
    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:
    459
    Cowboy \(Gregory A. Beamer\)
    Dec 3, 2003
  2. =B=
    Replies:
    3
    Views:
    3,836
  3. Keith-Earl
    Replies:
    4
    Views:
    3,638
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Nov 15, 2004
  4. saneman
    Replies:
    3
    Views:
    383
    saneman
    Jan 29, 2008
  5. Replies:
    0
    Views:
    540
Loading...

Share This Page