Click here to Skip to main content
15,918,211 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Since I went ASP.NET with my global.asa (making it a global.asax) the
application events are called just fine as well as the Session_OnStart event
but the Session_OnEnd event is not. What is wrong? My global.asax looks like
this:

XML
<%@ Application Language="VB" %>
<object id="myTB" class="System.Web.UI.WebControls.TextBox" scope="session" runat="server"/>
<object id="myTB2" class="System.Web.UI.WebControls.TextBox" scope="session" runat="server"/>
<object id="myLBL" class="System.Web.UI.WebControls.Label" scope="session" runat="server"/>

<script runat="server">

    Sub Session_OnStart()
        Application.Lock()
        Application("cssid") = HttpContext.Current.Session.SessionID
        Application("visitors") = Application("visitors") + 1
        Application("entrytime") = DateTime.Now.ToString
        Application.UnLock()

        'Dim EventLog1 As New System.Diagnostics.EventLog("Application", ".", "mySource")
        'EventLog1.WriteEntry("Session_OnStart fired!")
        'Context.Response.AppendToLog("Session_OnStart fired!")
    End Sub
    Sub Session_OnEnd()
        Application.Lock()
        Application("visitors") = Application("visitors") - 1
        Application("exittime") = DateTime.Now.ToString
        Application.UnLock()
        Response.Write("session end")
        'Dim st As String = "update duration set exittime= '" & Application("exittime") & "' where csid= '" & Application("cssid") & "'"
        ' System.Configuration.ConfigurationManager.AppSettings.Add(st)
        'Dim EventLog1 As New System.Diagnostics.EventLog("Application", ".", "mySource")
        'EventLog1.WriteEntry("Session_OnEnd fired!")
    End Sub
    Sub Application_OnError()
        Dim EventLog1 As New System.Diagnostics.EventLog("Application", ".", "mySource")
        EventLog1.WriteEntry("Error Occurred. Error info:" & Server.GetLastError().ToString())
    End Sub
    Sub Application_OnEnd()
        Application("totvisitors") = Application("visitors")
        Application("exittime") = DateTime.Now.ToString
    End Sub
    Sub Application_OnStart()
        Application("visitors") = 0
    End Sub


Any insights would be appreciated.

regards,

Sasikumar
Posted
Updated 29-Oct-10 8:14am
v2

You could read this KB article[^] which covers more details about the session events.

Cheers
Uwe
 
Share this answer
 
A session does not end when the user navigates away from your site or when they close the browser. The session may stay around for upwards of a half hour before you see an Seesion_OnEnd event.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900