我使用 FormsAuthentication 在我的 MVC4 应用程序中对用户进行身份验证。是否可以获取所有当前登录的用户?
2 回答
            0        
        
		
我不认为有任何这样的方法,但你可以试试这个
 List<MembershipUser> onlineUsers = Membership.GetAllUsers().Cast<MembershipUser>().Where(u => u.IsOnline == true).ToList();
对非常大的用户数据库使用 GetAllUsers 方法时要小心,因为 ASP.NET 页面中生成的 MembershipUserCollection 可能会降低应用程序的性能。
于 2013-01-31T12:39:33.473   回答
    
    
            0        
        
		
我必须先实例化集合,然后才能转换它:
private List<MembershipUser> GetAllUsers()
      {
          MembershipUserCollection MU_Coll = Membership.GetAllUsers();//.GetEnumerator()  ;//.Cast<MembershipUser>().Where(u => u.IsOnline == true).ToList();
          return MU_Coll.Cast<MembershipUser>().Where(u => u.IsOnline == true).ToList();
      } 
    于 2016-12-14T22:47:05.480   回答