How to Get List of User/Profile from Membership Provider?

后端 未结 2 1019
遥遥无期
遥遥无期 2020-12-19 15:15

I am utilising this Membership Provider. I am stuck with getting the User List + Profile (FirstName, LastName, Title etc etc)

I know that there is a method for Membe

2条回答
  •  执笔经年
    2020-12-19 15:32

    Membership.GetAllUsers() returns a MembershipUserCollection, which you can use to access individual MembershipUser. Example:

    MembershipUserCollection users = Membership.GetAllUsers();
    string email = users["some_username"].Email;
    

    You can also retrieve ProfileInfo in the similar way:

    ProfileInfoCollection profiles = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All);
    DateTime lastActivity = profiles["some_username"].LastActivityDate;
    

    However there are no FirstName and LastName properties by default, unless you manually specified them in your profile provider.

    Check out MembershipUser class and ProfileInfo class for more details. You might also wanna check out SqlProfileProvider class as an example of profile provider, unless you already have implemented one.

提交回复
热议问题