The best way to track current online users

I have a requirement that my site always displays the number of users who are currently online. For example, "35,741 users are currently online." This is not based on registration, just how many users are currently on my site. I tried using Session Start / Session End for this, however the end of the session is not reliable. Therefore, I get inflated numbers, as my session starts adding numbers, but the end of the session does not delete them, because it does not work.

There is no additional information to be gathered from this (reporting, etc.), she just asked for the number to appear. A very simple request that turns into a huge deal. Any help is appreciated.

EDIT:

I must indicate that I also tried to use a database for this. A simple table containing the session identifier and the last activity column. Every time I hit every page, I check to see if the session is in my database. If not, insert. If so, update the activity time. Then I run a procedure that sweeps a database that searches for sessions without activity in the last 20 minutes. This approach seems to have killed my SQL server and / or IIS. I had to restart the site.

+5
source share
7 answers

The best way, like you, but its duration. If this session does not have access to the page for 5 minutes or so, you can consider them more inactive.

+8
source
+3

, , "" . 5 . - . , , .

, .

+2

:

  • Active. .
+2

, - http , , "", , , , , , .

, , IP-, 5 (, "--" ).

0

, - ; .

, :

  • ,
  • HttpModule ( Global.asax) ( ).
  • , , N . " ".
  • .

, . , , - , Session_Start().

- , , , .

0

HttpContext.Current.Cache (, 20 ).

Global.asax.cs Application_PreRequestHandlerExecute "" , .

When the user explicitly logs out, delete his username from HttpContext.Current.Cache.

If you do this, at any given time, HttpContext.Current.Cache.Count will provide you with the number of current users.

Note: it is assumed that you are not using the cache for other purposes.

0
source

All Articles