1

I looked around for this issue and have found two approaches: use a database table to log users logging in and remove the entry when they log out or session ends; or use Membership.GetNumberOfUsersOnline(). I tried Membership version first but when I log in it shows the number to be zero (I am using form-based authentication, using AD in in Intranet web application and using Oracle DB).

I also created a table having user's ID (what is stored as aspnet_user's username), their aspnet_user's userid, login time stamp and logout time stamp. When user logs in, I add an entry and when users logs out, I remove the entry. The problem here is if session ends and Session_End() event is called I have no way of accessing user's ID (stored in session var) in order to remove the correct entry from table.

halfer
  • 19,824
  • 17
  • 99
  • 186
NoBullMan
  • 2,032
  • 5
  • 40
  • 93

1 Answers1

0

In membership, it records certain dates when you login and create activity that update the membership user, and I think the default behavior is to use that... if you are using a custom membership provider, make sure that default behavior is preserved.

Alternatively, if you want to roll your own, to determine number of users online, everytime the user takes an action that posts back, update the time on the user record, and then create a query that checks within a relative amount of time. Session_ENd is not a perfect way to determine if a user is online or not, because it may not always fire. User's don't always click the explicit logout button too, so that may not be a good indicator as well. But since session is 20 minutes, checking where an activity occured within the last 20 minutes is a rough indicator of logged in users...

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
  • Thanks Brian. When I check ora_aspnet_membership table, it shows my last login date as Nov. 2013! I am not sure why that is but I guess I am going to do the DB table version and update entry for a user every time there is activity. I guess I need a DB script to check if last_activity date/time is older than 20 minutes and remove that entry. Not sure if I can do it using a non-DB script. – NoBullMan Jul 23 '15 at 17:52