Keep track of who is online now

How do I track the number of ongoing sessions on my website?

+5
source share
5 answers

If you just want to find out who is browsing the pages on the small rinky-dink site, one way is to have a list of applications (or static) for all applications, as well as the date / time of the request. Whenever someone requests a page, deletes all the “old” hits (older than X minutes) and adds (or updates) the visitor information with the date / time,

Please note that for a really busy site this would probably be a bad idea. A slightly more scalable solution would be to have a “last visit” column in your user table and update it whenever a user requests a page. But that would not help track anonymous / non-registered users.

In any case, to find out who is “active”, you look at the data and find all the visits / users with the time of the last visit less than X minutes ago, where X is the number that you think is suitable. 20-60 minutes are usually good enough.

+2
source

- . , .

0

http ( global.asax), , .

RE:. , , , , eventargs. asp.net . , , - Session.Abandon(); , , , .

. 100% /, global.asax SessionEnd . , (, HttpContext.Current.Session, ).

0

, , SessionStateStoreProvider: http://msdn.microsoft.com/en-us/library/ms178587.aspx

GetItem RemoveItem, ASP.NET, ASP.NET . .

RemoveItem

:

ASP.NET, :

Create Procedure dbo.GetCurrentUsers
@ActiveSince DateTime
AS
    SELECT U.UserId, U.UserName, M.Email
    FROM aspnet_Users U 
    INNER JOIN aspnet_membership M ON M.UserId = U.UserId
    WHERE U.LastActivityDate > @ActiveSince
GO

@ActiveSince DateTime - .

var sessionState = (System.Web.Configuration.SessionStateSection)
              ConfigurationManager.GetSection("system.web/sessionState");
DateTime activeSince = DateTime.Now.AddMinutes(0 - sessionState.Timeout.TotalMinutes);

, , , , , script , aJAX , . , , .

0

Global.asax. Session_Start , , (, User, SessionId, StartTime, LastRequestTime).

, Session_Start GlobalList. , ( ). , , GlobalList, (, , ).

, Application_Start , , , ( , TimeSpan LastRequestTime-StartTime).

WebFarm, .

0

All Articles