Sessoni_End doesnt seem to be firing off.


Hello,

I have the following code that counts guests and logged in members.  However it seems on Session_End doesnt fire off.  I understand that it only fires off when Session.Abandon() is called or after the timeout is passed.  However neither seems to fire off the code.

I also have in webconfig

<sessionstate mode='inProc" cookieless='false' timout='25'/>

what am i missing?
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)

        Session.Timeout = 60
                
        Application.Lock()
        Application("ActiveUsers") = CInt(Application("ActiveUsers")) + 1
        Application.UnLock()
        RecordStatEntry("SessionStart")

    End Sub

    Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
        
                    
        ''If user is logged in remove from OnlineUsers Array, if they are not logged decrease guest by 1
        Application.Lock()
       
        Dim userCookie As HttpCookie = Nothing
        userCookie = HttpContext.Current.Request.Cookies("user")
            
        Dim userObj As New UserOnlineOffline(CInt(Request.Cookies("user")("id")), CInt(ConfigurationManager.AppSettings("clientid"))) 
        If CType(Application("OnlineUsers"), ArrayList).Contains(userObj) Then 'checking for the user in the application object "OnlineUsers" list
            CType(Application("OnlineUsers"), ArrayList).Remove(userObj) 'remove user from online list        
        End If
        
        Application("ActiveUsers") = CInt(Application("ActiveUsers")) - 1
        
        Application.UnLock() 'unlock application    
        Application.Clear()
        
        RecordStatEntry("SessionEnd")
     
       
        
    End Sub

Open in new window

lino_evolutionAsked:
Who is Participating?
 
CodeCruiserCommented:
Cookie comes from the client side. When the session is ending, there is no client side. Cookie is sent by the browser when requesting a page. Use session itself to store the ID.
0
 
CodeCruiserCommented:
So you waited for 25 minutes? And did you notice this in your session start?

 Session.Timeout = 60
0
 
lino_evolutionAuthor Commented:
Hey Code Cruiser, I did notice that as soon as I submitted this question, ived change the timeout to two minutes and it is still not firing off.

 RecordStatEntry("SessionEnd")  writes a record to the database telling me where the event fired how many guests at that point.

and i am seeing no such records.

any configuration in the IIS overrides these numbers cause i know there is a session timeout in the IIS Configuration.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
lino_evolutionAuthor Commented:
my counter keeps going higher and higher.. it seems session_End is never called...
0
 
CodeCruiserCommented:
Put a breakpoint on the session end sub and wait for session to timeout then see if its called.
0
 
lino_evolutionAuthor Commented:
I had put a breakpoint before and it had not worked now its working and now the problem is clearly more visible.

on session_End I am trying to retrieve the user cookie so I can compare its values to an arraylist of members that have logged in and if exists then that means a member's session has ended and remove it from the list...

what happens is as soon as it hits the cookie it creates an application error.  what happens to the cookie? shouldn't the cookie still be accessible?  

if it cant exist then my useronlineoffline obect stores the userID and the client ID, if i stored the current sessionID of that user and search the arraylist for that value and remove it upon finding it that would solve the problem or does the sessionID is not known on Session_End?


Dim userCookie As New VCCSecurity2003.VCCSecurity.VCCCookie("user") 'grabbing VCC cookie for access to userID and clientID        
        Dim userObj As New UserOnlineOffline(userCookie.Value("id"), userCookie.Value("clientid")) 'in the case of AHC beta, the clientID is the parent site ID which is 15
        If CType(Application("OnlineUsers"), ArrayList).Contains(userObj) Then 'checking for the user in the application object "OnlineUsers" list
            CType(Application("OnlineUsers"), ArrayList).Remove(userObj) 'remove user from online list   
        End If

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.