Membership list all user profiles

238 views Asked by At

I need to list all profiles of specific user but I cannot find how to do this.

public abstract ProfileInfoCollection FindProfilesByUserName(
    ProfileAuthenticationOption authenticationOption,
    string usernameToMatch
)

Returns me huge number of unwanted things here example:

"UserName": "Alex",
"IsAnonymous": false,
"IsDirty": false,
"LastActivityDate": "2013-08-16T00:44:30.98+03:00",
"LastUpdatedDate": "2013-08-16T00:25:15.663+03:00",
"Properties": [
     {
         "Name": "Name.First",
         "IsReadOnly": false,
         "DefaultValue": "",
         "PropertyType": "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
         "SerializeAs": 0,
         "Provider": {
             "ApplicationName": "/",
              "Name": "AspNetSqlProfileProvider",
              "Description": "SQL profile provider."
          },
          "Attributes": {
               "AllowAnonymous": false
          },
          "ThrowOnErrorDeserializing": false,
               "ThrowOnErrorSerializing": true
          }
]

Is there any way to list only the used / listed in web.config profiles?

Update: I also tried to write my one provider extension but I cant find where ProfileBase saving the profiles / profile groups.

Thanks!

1

There are 1 answers

0
Zilberman Rafael On BEST ANSWER

After long time of search I found only one way to solve the problem.

I wrote simple function for example:

public Dictionary<string, ProfileGroupBase> GetGroupProfiles(MembershipUser user, string[] groups)
{
     return groups.ToDictionary(group => group, GetUserProfile(user).GetProfileGroup);
}
public Dictionary<string, object> GetProfile(MembershipUser user, string[] properties)
{
        return properties.ToDictionary(prop => prop, prop => UserProfile(user).GetPropertyValue(prop));
}

And the usage:

x.GetGroupProfiles(Membership.GetUser("Rafael"), new[] { "Name" })