4

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 Membership.GetAllUsers() but I don't know how to combine this with FirstName, LastName that I stored in Profile Provider.

Thanks

samjudson
  • 56,243
  • 7
  • 59
  • 69
dcpartners
  • 5,176
  • 13
  • 50
  • 73

2 Answers2

5

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.

niaher
  • 9,460
  • 7
  • 67
  • 86
  • 4
    But the objects exposed by GetAllProfiles are of the ProfileInfo type, so they will not expose the custom Profile fields that the question is asking, i.e. FirstName, LastName etc – Fernando Neira Aug 20 '12 at 11:32
2

First when you create a user, create a profile with the same username using:

// Create an empty Profile for the new User
ProfileCommon p = (ProfileCommon) ProfileCommon.Create("username", true);

Then to retrieve it next time..

// Retrieve a particular profile
ProfileCommon userProfile = Profile.GetProfile("username");

Thanks.

this. __curious_geek
  • 42,787
  • 22
  • 113
  • 137