Session_OnEnd Not Firing

Discussion in 'Site Programming, Development and Design' started by lewbeach, Feb 14, 2011.

  1. I have a classic ASP site and am using the Session_OnEnd event in global.asa to clean out a temporary table in a SQL DB when a session ends, in case a user does not exit "cleanly". I've used this method on many sites and other servers in the past.
    This works fine on my local development server (WinXP, IIS version 5.1), but not on the Winhost server.
    The Session_OnStart event works OK on the Winhost server, but not the Session_OnEnd.
    This is the same condition I have on another local development machine I'm using, (Win7 Home Premium, IIS version 7.5).
    I've searched the web and the only thing I've found is that the OnEnd event may be running under a different user account. But I don't see any way on the control panel to correct this.
    Help! Thanks in advance.
     
    Last edited by a moderator: Oct 14, 2015
  2. Ray

    Ray

    What makes you think that Session_OnEnd is not working? Are you getting any error messages? Do you have instructions on how we can replicate this on our end?
     
  3. Thanks for responding.
    It may be that the Session_OnEnd event is firing, but the code within is not being executed. I can tell this because the rows in the referenced database table are not being deleted when the session ends. There are no error messages.

    As I said, this all works fine on my local server, and has for many other applications over many years on many other servers. It's only on the newer versions of IIS that it does not work. That's why I think it may be a permissions issue.

    The code I'm using in "root/spanish/global.asa is below:"

    Sub Session_OnEnd

    sDSN = "Provider=SQLOLEDB;Data Source=s03.Winhost.com;Initial Catalog=DB_17683_myageq;User Id=[myuserid];Password=[mypassword];Connect Timeout=15;Network Library=dbmssocn;"

    ' Delete from wrong_answers table in case user bugged out of quiz for any reason:

    'dim myID
    'myID = CStr(Session.SessionID)

    sSQL = "delete from wrong_answers where quiz_id = " & Session.SessionID
    set cn = Server.CreateObject("ADODB.Connection")
    cn.Open(sDSN)
    set rs = cn.Execute(sSQL)
    set rs = Nothing
    cn.close
    set cn = Nothing
    End Sub
     
    Last edited by a moderator: Oct 14, 2015
  4. Ray

    Ray

    Maybe the session ID is not being passed correctly or it is being lost before it gets to the line.

    sSQL = "delete from wrong_answers where quiz_id = " & Session.SessionID

    Try typing a resposne.write session.sessionID to verify if it is passed correctly.
     
  5. @lewbeach -- I don't know if this is relevant but I came up against something like this recently. I'm using ASP.NET MVC, but I found that session_end does *not* fire if you use SQL-backed session state rather than inproc. This caught me by surprise and I had to rewrite a decent chunk of my app :(
     

Share This Page