【问题标题】:How to Get List of User/Profile from Membership Provider?如何从会员提供者获取用户/个人资料列表?
【发布时间】:2010-10-29 13:32:06
【问题描述】:

我正在使用此会员资格提供商。我一直在获取用户列表 + 个人资料(名字、姓氏、头衔等)

我知道有一个 Membership.GetAllUsers() 方法,但我不知道如何将它与存储在 Profile Provider 中的 FirstName、LastName 结合起来。

谢谢

【问题讨论】:

    标签: asp.net asp.net-membership


    【解决方案1】:

    Membership.GetAllUsers() 返回一个 MembershipUserCollection,您可以使用它来访问单个 MembershipUser。示例:

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

    您也可以通过类似的方式检索 ProfileInfo:

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

    但是,默认情况下没有 FirstName 和 LastName 属性,除非您在配置文件提供程序中手动指定它们。

    查看MembershipUser classProfileInfo class 了解更多详情。您可能还想查看 SqlProfileProvider class 作为配置文件提供者的示例,除非您已经实现了。

    【讨论】:

    • 但 GetAllProfiles 公开的对象属于 ProfileInfo 类型,因此它们不会公开问题所要求的自定义 Profile 字段,即 FirstName、LastName 等
    【解决方案2】:

    首先,当您创建用户时,使用相同的用户名创建配置文件:

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

    那下次再取回来..

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

    谢谢。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-08
      • 2016-07-29
      • 1970-01-01
      • 2014-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多