Session Question

  • Thread starter Thread starter Patrick Olurotimi Ige
  • Start date Start date
P

Patrick Olurotimi Ige

I'm tracking usersOnline by adding this code below in my Global.asax
file.But i noticed that when a user logs in it keeps adding a new user
which thats fine..but when a user logs of it still retains the
user(session) for sometime instead of reducing it by one!

I'm thinking of maybe i should change something in IIS relating to
Session?

Any ideas..


Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session is started
Session("Start") = Now
Application.Lock()
Application("ActiveUsers") = CInt(Application("ActiveUsers")) +
1
Application.UnLock()
End Sub

--------------------------
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
Application.Lock()
Application("ActiveUsers") = CInt(Application("ActiveUsers")) -
1
Application.UnLock()
End Sub
 
By default a session ends after 20 minutes of no page requests from the
user.
That would be when the Session_End event normally fires.
 
Thx Steve..
So it means if i change the Session Timeout in Web.Config to a lower
value it should be fine?

And another question which one overrides Session timeout in Web.Config
or IIS..
 
re:
So it means if i change the Session Timeout in
Web.Config to a lower value it should be fine?

Yes.
It would also be fine if you change it to a higher value.

re:
which one overrides Session timeout
in Web.Config or IIS..

Web.config overrides.



Juan T. Llibre
===========
 
Thx Juan for the reply..
Setting the value to higher level or lower level ..
Which one best fits for tracking UsersOnline?
 
Lower would be more accurate for tracking users online, but it might annoy
your users if you set it too low.
 
re:
Setting the value to higher level or lower level ..
Which one best fits for tracking UsersOnline?

That would depend on your user's needs
or on your website's needs.


Tracking sessions consumes server resources
( memory and processing time, for the most part ).

If you need to track user information to such
an extent that you need a longer session level.
then increasing it would make sense.

Otherwise, increasing the session time
would be a waste of server resources.

You should strive for the least session time value
which serves your user/server needs.



Juan T. Llibre
===========
 
Back
Top