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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CodeCruiserCommented:
So you waited for 25 minutes? And did you notice this in your session start?

 Session.Timeout = 60
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.
lino_evolutionAuthor Commented:
my counter keeps going higher and higher.. it seems session_End is never called...
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

CodeCruiserCommented:
Put a breakpoint on the session end sub and wait for session to timeout then see if its called.
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

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.