简体   繁体   中英

In ASP.NET MVC 3 with built-in user login using Forms, how can I retrieve a list of currently logged in users?

I am making an app in C# using MVC 3 and I'm trying to learn about the built-in user stuff that comes for free (in the Membership class).

I want to make a page on my site that lists every user who is currently logged in. Is there a way to do this easily?

var onlineUsers = Membership.GetAllUsers()
    .Cast<MembershipUser>().Where(u => u.IsOnline);

Make sure you "bump" the users to be online.

You can learn more on how to retrieve list of users and bind it to a view in this previously asked question on StackOverflow:

List of Users and Role using Membership Provider

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM