Track Current Users
26 May 2004

This afternoon I was reading an article online about keeping track of site statistics by using the ASP.Net global.asax file when I decided to add this quick feature to my site - current users.

If you scroll down to the bottom of the page, you will see a number in parentheses in the lower right hand corner. This represents the number of users that have active sessions (they have made a request within the past 20 minutes.)

I added this to the page by making two small code changes. First, I added this to the global.asax file:

Public Sub Application_Start(sender As Object, e as EventArgs)
      Application("CurrentUsers") = 0
End Sub
Public Sub Session_Start(sender As Object, e as EventArgs)
Application.Lock
      Application("CurrentUsers") = Application("CurrentUsers")+1
Application.UnLock
End Sub
Public Sub Session_End(sender As Object, e as EventArgs)
Application.Lock
      Application("CurrentUsers") = Application("CurrentUsers")-1
Application.UnLock
End Sub

Then I added the following small snippet to my footer page:
Response.Write Application("CurrentUsers")

That is it! Now I am able to track how many active sessions are on nicnic at any given moment in time.