【问题标题】:Membership list all user profiles成员资格列表所有用户配置文件
【发布时间】:2013-08-16 05:39:13
【问题描述】:

我需要列出特定用户的所有个人资料,但我找不到如何做到这一点。

public abstract ProfileInfoCollection FindProfilesByUserName(
    ProfileAuthenticationOption authenticationOption,
    string usernameToMatch
)

在这里返回大量不需要的东西示例:

"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
          }
]

有没有办法只列出 web.config 配置文件中使用的 / 列出的?

更新: 我还尝试编写我的一个提供程序扩展,但我找不到 ProfileBase 保存配置文件/配置文件组的位置。

谢谢!

【问题讨论】:

    标签: c# .net membership-provider sqlprofileprovider


    【解决方案1】:

    经过长时间的搜索,我发现只有一种方法可以解决问题。

    我写了简单的函数例如:

    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));
    }
    

    及用法:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-05
      • 1970-01-01
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-27
      相关资源
      最近更新 更多