2

what is the best simple way to show who is online in c# without using membership control? Is the only way is using session ?

2 Answers 2

2

You can do this via:

var onlineUsers = System.Web.Security.Membership.GetAllUsers()
    .Cast<System.Web.Security.MembershipUser>()
    .Where(user => user.IsOnline);

But you will need to cache/refresh this properly, since it can be a very expensive operation.

0

yes go to global.asax and create a new List<> of your User Class type in application_start event and save it to Cache

    List<User> OnlineUsers = new List<User>();
    Cache.Insert ("onlineuser",OnlineUsers,...);

and in your loginButton code get the list from cache and add the logged in user

    User loggedin =someHelperCode.GetUser (txtUserName.Text,txtPassword.Text);
    ((List<User>)Cache["onlineuser"]).Add (loggedin);

and when a user logs out do the same and remove the user

and you can just bind the list to any lost bound control

1
  • 1
    What happens if the user is logged out because their session expires rather than having explicitly logged out? (beaten by Kaf - must type faster next time)
    – KazR
    Mar 18, 2012 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.