Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find how many people are online in a website

Tags:

asp.net

I have to show how many people are online in that site. The site has developed by using ASP.NET 2.0. Currently I am using the Session start (increase by 1) and Session End Event (decrease by 1) in Global.asax. But the Session_End Event not calling properly most of the times. Is there any better way to achieve this?

like image 235
Kthevar Avatar asked Dec 08 '22 06:12

Kthevar


2 Answers

You're not going to get much better then incrementing in Session_Start and decrementing in Session_End unless you use some other means like a database.

When you are authenticating your requests you could update a timestamp in the database to show that the user has been active, and after a given time (say 15 minutes), the query that collects the number of concurrent users ignores that row in the database (thus decrementing the count).

like image 132
John Rasch Avatar answered Jan 05 '23 20:01

John Rasch


A quick Google search revealed a handy way of doing this with a HttpModule.

All in all, Yohann did a great job with this. It does implement a set timeout that was suggested above, but otherwise there is no set way of doing this accurately outside of checking the server's perfmon.exe and checking the WebService >> WebAppPool's count of current connections.

When I implemented this myself I used a SQL Server table to store a date/time and user info on authentication. I decremented the count by re-assesing and matching the IP addresses whenever I had to refresh the data cache (once every 10 mins).

like image 39
Jonathan Avatar answered Jan 05 '23 20:01

Jonathan