Do you want to know how many active users are present on
your site?
Well, I don't know if you can EXACTLY know the number of
active users
on the site, but here is a good heuristic.
- Define a variable in the global.ascx.cs file
- Increment this variable in the Session_Start
- Decrement this variable in the Session_End
NOTE: You need to check if Session_Start and Session_End is
thread
safe, if you just want to be safe, just make sure you
increment/decrement the variable atomically.
This value of the variable should be able to give you the
total number
of sessions, which should be a good estimate for the number
of active
users.
There are problems with this approach, i.e.
- someone could open 3 different browser instances to your
site as 3
different people, rather than 1 person.
- Also, this method is for the In-Process session model for
ASP.NET, if
you have a site which is balanced across a web farm, then
you need to
have this variable in the database and update this value in
the
database.
However, you can solve these problems depending on your
situation.
I hope this was helpful.
Sincerely,
Bobby
|