Global.asa - Session_OnEnd Question ..

Discussion in 'ASP General' started by MostlyH2O, Jul 28, 2003.

  1. MostlyH2O

    MostlyH2O Guest

    Hi Folks,

    I'm having a hard time getting my Session_OnEnd event to fire in my
    global.asa.
    Here's what I have:

    <SCRIPT LANGUAGE=VBSCRIPT RUNAT=Server>
    SUB Session_OnStart
    Session.TimeOut = 30
    END SUB

    Sub Session_OnEnd
    Response.Redirect("http://mydomain.com/mylogin.asp")
    End Sub
    </SCRIPT>

    I made a simple page to call the session.abandon - to test the OnEnd event.
    But it doesn't fire. I have set the session.timeout to 1 and also waited for
    the default 20 to pass. I just can't get that redirect to occur when the
    session ends.

    I know the global.asa is set up properly, because the OnStart event WILL
    fire if I move my redirect statement to the SUB Session_OnStart routine.

    Thanks very much for any help.

    Clear Skies,
    Jack Coletti
     
    MostlyH2O, Jul 28, 2003
    #1
    1. Advertising

  2. MostlyH2O

    Roy in Guest

    But obvously this guy's browser was not closed in this case, because he was
    testing to see if the redirection would occur.
    http://www.aspfaq.com/2078

    this article say that there is a bug, not that his test should fail because
    his computer might be turned off.

    Ray is at <%=sLocation%>" but the lights are off

    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    news:...
    > I suggest you do something a little different, like:
    >
    > Sub session_onstart()
    > session("active") = true
    > End Sub
    >
    > And then use something like
    > If Not(session("active")) Then response.redirect "/mylogin.asp"
    >
    >
    > See here for the reasons.
    > http://www.aspfaq.com/2078
    >
    > When the session ends, the browser could be closed, and the user's

    computer
    > may even be turned off, unplugged, and thrown away. How could you do a
    > redirect then?
    >
    > Ray at home
    >
    >
    > --
    > Will trade ASP help for SQL Server help
    >
    >
    > "MostlyH2O" <> wrote in

    message
    > news:XU1Va.172194$...
    > > Hi Folks,
    > >
    > > I'm having a hard time getting my Session_OnEnd event to fire in my
    > > global.asa.
    > > Here's what I have:
    > >
    > > <SCRIPT LANGUAGE=VBSCRIPT RUNAT=Server>
    > > SUB Session_OnStart
    > > Session.TimeOut = 30
    > > END SUB
    > >
    > > Sub Session_OnEnd
    > > Response.Redirect("http://mydomain.com/mylogin.asp")
    > > End Sub
    > > </SCRIPT>
    > >
    > > I made a simple page to call the session.abandon - to test the OnEnd

    > event.
    > > But it doesn't fire. I have set the session.timeout to 1 and also waited

    > for
    > > the default 20 to pass. I just can't get that redirect to occur when

    the
    > > session ends.
    > >
    > > I know the global.asa is set up properly, because the OnStart event WILL
    > > fire if I move my redirect statement to the SUB Session_OnStart routine.
    > >
    > > Thanks very much for any help.
    > >
    > > Clear Skies,
    > > Jack Coletti
    > >
    > >
    > >

    >
    >
     
    Roy in, Jul 28, 2003
    #2
    1. Advertising

  3. MostlyH2O

    Roy in Guest

    Actually what I meant to say is that Ray was right, but you have to read the
    Entire article- just like I keep saying.

    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    news:...
    > I suggest you do something a little different, like:
    >
    > Sub session_onstart()
    > session("active") = true
    > End Sub
    >
    > And then use something like
    > If Not(session("active")) Then response.redirect "/mylogin.asp"
    >
    >
    > See here for the reasons.
    > http://www.aspfaq.com/2078
    >
    > When the session ends, the browser could be closed, and the user's

    computer
    > may even be turned off, unplugged, and thrown away. How could you do a
    > redirect then?
    >
    > Ray at home
    >
    >
    > --
    > Will trade ASP help for SQL Server help
    >
    >
    > "MostlyH2O" <> wrote in

    message
    > news:XU1Va.172194$...
    > > Hi Folks,
    > >
    > > I'm having a hard time getting my Session_OnEnd event to fire in my
    > > global.asa.
    > > Here's what I have:
    > >
    > > <SCRIPT LANGUAGE=VBSCRIPT RUNAT=Server>
    > > SUB Session_OnStart
    > > Session.TimeOut = 30
    > > END SUB
    > >
    > > Sub Session_OnEnd
    > > Response.Redirect("http://mydomain.com/mylogin.asp")
    > > End Sub
    > > </SCRIPT>
    > >
    > > I made a simple page to call the session.abandon - to test the OnEnd

    > event.
    > > But it doesn't fire. I have set the session.timeout to 1 and also waited

    > for
    > > the default 20 to pass. I just can't get that redirect to occur when

    the
    > > session ends.
    > >
    > > I know the global.asa is set up properly, because the OnStart event WILL
    > > fire if I move my redirect statement to the SUB Session_OnStart routine.
    > >
    > > Thanks very much for any help.
    > >
    > > Clear Skies,
    > > Jack Coletti
    > >
    > >
    > >

    >
    >
     
    Roy in, Jul 28, 2003
    #3
  4. MostlyH2O

    Ray at Guest

    It is late on a Sunday night (in the easter time zone anyway). You should
    not be drunk. ;]

    Ray at home

    --
    Will trade ASP help for SQL Server help


    "Roy in <%=H.E.Double Toothpicks $>" <> wrote in
    message news:ef$...
    > Actually what I meant to say is that Ray was right, but you have to read

    the
    > Entire article- just like I keep saying.
    >
    > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    > news:...
    > > I sugge
     
    Ray at, Jul 28, 2003
    #4
  5. MostlyH2O

    TomB Guest

    Ah yes the easter time zone, where every morning chocolate eggs are found
    scattered throughout the home.

    If the Session has ended, then the user hasn't requested anything from the
    server. Since the server can't send anything to the client without a
    request, you won't be able to redirect anywhere.

    If the user was browsing around your site then his Session("Active") ="true"
    as set in Session_OnStart. Then he goes for a nap and his session times
    out. As soon as he clicks on a link or refreshes his screen, his
    Session("Active") will again be set to "true" as a new session will have
    begun.
    The response.redirect will never be called in the Session_OnEnd.

    If the goal is merely to ensure someone is logged in and their session is
    active. It would be more logical to set the Session("Active")=true in the
    login processing page, then checking that it's still valid at the top of
    every page--a good job for an #include.




    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    news:...
    > It is late on a Sunday night (in the easter time zone anyway). You should
    > not be drunk. ;]
    >
    > Ray at home
    >
    > --
    > Will trade ASP help for SQL Server help
    >
    >
    > "Roy in <%=H.E.Double Toothpicks $>" <> wrote in
    > message news:ef$...
    > > Actually what I meant to say is that Ray was right, but you have to read

    > the
    > > Entire article- just like I keep saying.
    > >
    > > "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    > > news:...
    > > > I sugge

    >
    >
     
    TomB, Jul 28, 2003
    #5
  6. I'm going to assume what you are trying to accomplish is to require the user
    to log back in after a period of inactivity. As was pointed out in previous
    posts, this can not be accomplished using the Session_OnEnd sub in the
    global.asa file.

    The method I use for this is to simply use a meta element in HTML and
    redirect the browser after a period of time equivalent to my session timeout
    on the server. I redirect to a page informing the user that their session
    has timed out.

    On the page I want to timeout, I put:
    <% strThisPageURL = "http://" & Request.ServerVariables("SERVER_NAME") &
    Request.ServerVariables("URL")
    <meta http-equiv="refresh" content="1200; URL=<% Response.Write "http://" &
    Request.ServerVariables("SERVER_NAME") & "/ExpiredLogIn.asp?U=" &
    strThisPageURL %>">

    The page ExpiredLogIn.asp is:
    <html>
    <head>
    <title>Log-In Expired</title>
    </head>
    <%If Not IsEmpty(Request.QueryString("U")) Then strPreviousPageURL =
    Request.QueryString("U")%>
    <body>
    <p align="center">&nbsp;</p>
    <h3 align="center">Your Log-in has expired due to inactivity.</h3>
    <h3 align="center">If you wish to log-in again, click <a
    href="LogInForm.asp?U=<%=strPreviousPageURL%>">here</a>.</h3>
    </body>
    </html>

    And in my login page, it looks for the QueryString for the URL of the timed
    out page and redirects there after a successful login.

    HTH
    Mark
     
    Mark Hastings, Jul 28, 2003
    #6
  7. MostlyH2O

    MostlyH2O Guest

    Thanks for all the help, good people.

    Yes, I would have toiled for days trying to get the global.asa to redirect
    the user to the login page after the session timed out. And, I *was* trying
    to avoid checking the session state at the top of each of the 47 pages that
    make up my utility.

    Thanks for setting me straight :)

    Clear Skies,
    Jack Coletti
     
    MostlyH2O, Jul 28, 2003
    #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. Soha El-Saeed

    Global.asa and Session_OnEnd

    Soha El-Saeed, Feb 4, 2004, in forum: ASP General
    Replies:
    1
    Views:
    153
    John Blessing
    Feb 4, 2004
  2. Olivier SOW

    session_OnEnd dans le global.asa never fired

    Olivier SOW, Oct 27, 2004, in forum: ASP General
    Replies:
    6
    Views:
    175
    Bob Barrows [MVP]
    Oct 28, 2004
  3. Bill

    Global.asa and Session_OnEnd

    Bill, Feb 11, 2005, in forum: ASP General
    Replies:
    4
    Views:
    120
  4. steven scaife

    Global.asa Session_OnEnd

    steven scaife, Sep 1, 2005, in forum: ASP General
    Replies:
    3
    Views:
    162
    Evertjan.
    Sep 2, 2005
  5. global.asa @ Session_OnEnd

    , Jul 13, 2006, in forum: ASP General
    Replies:
    1
    Views:
    121
    Mike Brind
    Jul 13, 2006
Loading...

Share This Page