views:

185

answers:

2

I am looking for a way to search through every users profile using the standard ASP.Net Profile Provider. Is this possible, or should I create a new Profile Provider?

Here is the scenario:

  • User registers
  • User sets up their profile (favorite color, favorite book, country, etc)
  • User is then able to browse other users who, for instance, have a favorite color of "Green"

I would like to use this all through the membership/profile providers without having to code against the database directly.

A: 

I believe the standard provider will only work for the current user. You would need a custom profile provider to retrieve the information for other users. Fortunately it is really easy to do. That link has an example of a custom provider that allows you to retrieve the profiles of other users. If you use his example, be sure to note the person's comment about removing the profile section from your web.config. I had to do that to make mine work correctly.

nshaw
+1  A: 

The functionality you want is included in the Profile API.

You can get an individual users profile using:

HttpProfile profile = Profile.GetProfile("Fred");

You can get all the profiles using:

var allUsers = Membership.GetAllUsers();
foreach (MembershipUser user in allUsers)
{
    var prof = ProfileBase.Create(user.UserName, true);
}
Rob Windsor