【问题标题】:ProfileProvider: retrieve list of all profilesProfileProvider:检索所有配置文件的列表
【发布时间】:2009-09-10 09:59:43
【问题描述】:

我正在开发一个带有 ActiveDirectoryMembershipProvider 和 SqlProfileProvider 的 asp.net 内网网站。

我的网站的要求之一是有一个“生日”页面,这需要我列出所有个人资料并从中检索生日信息。

我是这样处理这个问题的:

  • 调用 Membership.GetAllUsers() 静态方法;
  • 遍历用户列表并从成员的用户名中检索配置文件

但是,由于以下原因,这种方法失败了:

  • webapp 正在模拟当前登录的用户以检索其 AD 详细信息(web.config 中的身份 impersonate="true"),因此在尝试调用 GetAllUsers 时出现异常“访问被拒绝”
  • 如果我确实尝试让 web 应用程序模拟超级用户帐户,那么 AD 会以用户名@域名格式返回用户名,但在我的配置文件提供程序中,它们最初存储为域名\用户名格式。

那么,您将如何解决这个问题来检索组织中任何成员的完整个人资料列表?

【问题讨论】:

    标签: asp.net security membership profile


    【解决方案1】:

    虽然我以前从未这样做过,但您可以尝试创建一个辅助模拟上下文,在建立后,对GetAllUsers 的调用应该会成功。

    看看http://chiragrdarji.blogspot.com/2007/03/impersonation-using-code.html,这个小伙子似乎通过使用System.Security.Principal.WindowsIdentity 类和System.Security.Principal.WindowsImpersonationContext 实现了安全上下文的改变。可能值得一试。

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 是的 - 在尝试找到另一种方法之前,请务必仔细查看现有方法。
      【解决方案3】:
      ProfileInfoCollection profiles = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All);
      foreach (ProfileInfo pi in profiles)
      {
          ProfileCommon p = Profile.GetProfile(pi.UserName);
          countries.Add(p.Country);        
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-01-23
        • 1970-01-01
        • 2015-06-23
        • 1970-01-01
        • 2012-04-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多