Does a Session timeout Generate an event?

Discussion in 'ASP .Net' started by David Laub, May 5, 2004.

  1. David Laub

    David Laub Guest

    Is it possible to know when an asp.net session has timed out? Is there some
    sort of timer event?

    Thanks
    David Laub, May 5, 2004
    #1
    1. Advertising

  2. David Laub

    CW Guest

    Put your code in the

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the session ends
    End Sub

    handler of the global.asax file.

    Same as in the ASP classic.

    "David Laub" <> wrote in message
    news:...
    > Is it possible to know when an asp.net session has timed out? Is there

    some
    > sort of timer event?
    >
    > Thanks
    >
    >
    CW, May 5, 2004
    #2
    1. Advertising

  3. Session_OnEnd() in your global.asax file is called whenever the session
    times out (or is abandoned explicitly).

    -- Alex Papadimoulis


    "David Laub" <> wrote in message
    news:...
    > Is it possible to know when an asp.net session has timed out? Is there

    some
    > sort of timer event?
    >
    > Thanks
    >
    >
    Alex Papadimoulis, May 5, 2004
    #3
  4. David Laub

    David Laub Guest

    Thanks - but that just raises what I guess should have been my REAL
    question:

    Is there a way of detecting a "real" time out - i.e. the user of the web app
    still has a page open in his/her browser, but didn't click a post-back for
    20 minutes
    versus the user explicitly closed the page/browser

    what I specifically want is to display an error page on a time out - but if
    just put unconditional code in Session_End, I'll have no way of knowing
    what's an error and what isn't.
    "CW" <a> wrote in message news:u$...
    > Put your code in the
    >
    > Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
    > ' Fires when the session ends
    > End Sub
    >
    > handler of the global.asax file.
    >
    > Same as in the ASP classic.
    >
    > "David Laub" <> wrote in message
    > news:...
    > > Is it possible to know when an asp.net session has timed out? Is there

    > some
    > > sort of timer event?
    > >
    > > Thanks
    > >
    > >

    >
    >
    David Laub, May 5, 2004
    #4
  5. David,

    That can only be handled with client-side code. You'll need to use the
    SetTimeout Javascript function. You'll probably need a work around to get it
    to handle 20+ minutes, since i believe it works in miliseconds. But, that's
    not a terrible deal, I'm sure you could figure it out.

    --Alex Papadimoulis

    "David Laub" <> wrote in message
    news:...
    > Thanks - but that just raises what I guess should have been my REAL
    > question:
    >
    > Is there a way of detecting a "real" time out - i.e. the user of the web

    app
    > still has a page open in his/her browser, but didn't click a post-back for
    > 20 minutes
    > versus the user explicitly closed the page/browser
    >
    > what I specifically want is to display an error page on a time out - but

    if
    > just put unconditional code in Session_End, I'll have no way of knowing
    > what's an error and what isn't.
    > "CW" <a> wrote in message news:u$...
    > > Put your code in the
    > >
    > > Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
    > > ' Fires when the session ends
    > > End Sub
    > >
    > > handler of the global.asax file.
    > >
    > > Same as in the ASP classic.
    > >
    > > "David Laub" <> wrote in message
    > > news:...
    > > > Is it possible to know when an asp.net session has timed out? Is

    there
    > > some
    > > > sort of timer event?
    > > >
    > > > Thanks
    > > >
    > > >

    > >
    > >

    >
    >
    Alex Papadimoulis, May 5, 2004
    #5
  6. David Laub

    CW Guest

    This is how I would do it.

    Craft a cookie that expires, say, in 30 minutes (i.e., a non-persistent
    cookie that times out later than a session cookie).

    If your Session_start even handler, look for this cookie. If it is present,
    then it indicates that user has timed out, but haven't closed the browser.

    If the cookie doesn't exist, either it is because the user has not posted
    back for 30 mins or the user closed browser (which would remove a
    non-persistent cookie).

    I guess you just have to determine what is an optimum time for the cookie
    expiry time in order to distinguish between time-out vs browser closing.

    HTH

    "David Laub" <> wrote in message
    news:...
    > Thanks - but that just raises what I guess should have been my REAL
    > question:
    >
    > Is there a way of detecting a "real" time out - i.e. the user of the web

    app
    > still has a page open in his/her browser, but didn't click a post-back for
    > 20 minutes
    > versus the user explicitly closed the page/browser
    >
    > what I specifically want is to display an error page on a time out - but

    if
    > just put unconditional code in Session_End, I'll have no way of knowing
    > what's an error and what isn't.
    > "CW" <a> wrote in message news:u$...
    > > Put your code in the
    > >
    > > Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
    > > ' Fires when the session ends
    > > End Sub
    > >
    > > handler of the global.asax file.
    > >
    > > Same as in the ASP classic.
    > >
    > > "David Laub" <> wrote in message
    > > news:...
    > > > Is it possible to know when an asp.net session has timed out? Is

    there
    > > some
    > > > sort of timer event?
    > > >
    > > > Thanks
    > > >
    > > >

    > >
    > >

    >
    >
    CW, May 6, 2004
    #6
    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. Do
    Replies:
    2
    Views:
    6,342
  2. bruce barker

    Re: ASPX Page Timeout - Session Timeout

    bruce barker, Jul 20, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    11,097
    ASP.Confused
    Jul 20, 2004
  3. =?Utf-8?B?Q3JhaWc=?=

    formsauthentication timeout & session timeout

    =?Utf-8?B?Q3JhaWc=?=, Aug 10, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,633
    =?Utf-8?B?RU5JWklO?= .enizin.net>
    Aug 10, 2005
  4. =?Utf-8?B?Um9iSEs=?=
    Replies:
    4
    Views:
    5,250
    =?Utf-8?B?Um9iSEs=?=
    Apr 11, 2007
  5. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,268
    Brian Candler
    Oct 6, 2004
Loading...

Share This Page