• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

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

0
lino_evolution
Asked:
lino_evolution
  • 3
  • 3
1 Solution
 
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
 
lino_evolutionAuthor Commented:
my counter keeps going higher and higher.. it seems session_End is never called...
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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
 
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now