Session Question

  • Thread starter Patrick Olurotimi Ige
  • 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
 
S

Steve C. Orr [MVP, MCSD]

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

Patrick Olurotimi Ige

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

Juan T. Llibre

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

Patrick Olurotimi Ige

Thx Juan for the reply..
Setting the value to higher level or lower level ..
Which one best fits for tracking UsersOnline?
 
S

Steve C. Orr [MVP, MCSD]

Lower would be more accurate for tracking users online, but it might annoy
your users if you set it too low.
 
J

Juan T. Llibre

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top