I need all active users logged on my website. I know I can take my logged-in user:
var currentUser = manager.FindById(User.Identity.GetUserId());
but how can I take all?
I need all active users logged on my website. I know I can take my logged-in user:
var currentUser = manager.FindById(User.Identity.GetUserId());
but how can I take all?
Create a field in user table named "IsLogin". Set IsLogin = 0 when user Signup. Update the field whenever user logged in to the system i.e. IsLogin = 1
Now in order to get all logged-in users : Check all records in a user table whose have IsLogin = 1 Your choice save the result in user object or just store ids or names of those users who are logged-in Hence you store the result in array or any collection (i.e List) Now you can easily enumerate list from start till end to get all logged-in users.
I used this method, It is the most recommended way.
ASP.NET membership has a feature that works for FormsAuthentication. Otherwise you need to write to a persistent store somewhere the most recent activity date & then query that table for all users active within a certain window. A web app is stateless, so "actively logged" in is a fictional abstraction we imagine over a stateless protocol. After a request is over the server has forgotten about you. Another hack might be to count how many sessions are still alive if you are using sql session store.