ProfileProvider:检索所有配置文件的列表
我正在使用 ActiveDirectoryMembershipProvider 和 SqlProfileProvider 开发一个 asp.net Intranet 网站。
我的网站的要求之一是有一个“生日”页面,这需要我列出所有个人资料并从中检索生日信息。
我按如下方式处理该问题:
- 调用 Membership.GetAllUsers() 静态方法;
- 遍历用户列表并从成员的用户名中检索配置文件
但是,此方法因以下原因而失败:
- web 应用程序正在模拟当前登录的用户以检索其 AD 详细信息(web.xml 中的 Identity impersonate="true")。配置),因此在尝试调用 GetAllUsers 时出现异常“访问被拒绝”
- 如果我确实尝试使 Web 应用程序模拟超级用户帐户,则 AD 以用户名@域名格式返回用户名,但在我的个人资料中它们最初存储为域名\用户名格式。
那么,您将如何解决这个问题来检索组织中任何成员的完整配置文件列表?
I'm developing an asp.net intranet website with a ActiveDirectoryMembershipProvider and a SqlProfileProvider.
One of the requirements of my website is to have a "Birthdays" page, which would require me to list all profiles and retrieving the birthday information from it.
I approached the problem as follows:
- Invoke the Membership.GetAllUsers() static method;
- Iterate through the list of users and retrieve the profile from the member's user name
This approach, however, failed for the following reasons:
- The webapp is impersonating the current logged user to retrieve its AD details (identity impersonate="true" in the web.config), so I get an exception "access is denied" when trying to invoke the GetAllUsers
- If I do try to make the webapp impersonate a super user account then AD returns the user names as username@domain-name format, but in my profile provider they were initially stored as domain-name\username format.
So, how would you go around this problem to retrieve the whole list of profiles for any member of the organization?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尽管我以前从未这样做过,但您可以尝试创建辅助模拟上下文,建立后,对
GetAllUsers
的调用应该会成功。看看 http://chiragrdarji.blogspot.com/2007/ 03/impersonation-using-code.html,这个小伙子似乎通过使用
System.Security.Principal.WindowsIdentity
类以及System.Security 实现了安全上下文的更改.Principal.WindowsImpersonationContext
。可能值得一看。Although I've never done it before, you could attempt to create a secondary impersonation context, that when established, the call to
GetAllUsers
should succeed.Have a look at http://chiragrdarji.blogspot.com/2007/03/impersonation-using-code.html, this chap appears to have achieved a change in security context by using
System.Security.Principal.WindowsIdentity
class along withSystem.Security.Principal.WindowsImpersonationContext
. Might be worth checking out.有一个 ProfileManager 具有 GetAllProfiles() 方法:
http://msdn.microsoft.com/en-us/library/system.web.profile.profilemanager.getallprofiles.aspx
There is a ProfileManager with the a method GetAllProfiles():
http://msdn.microsoft.com/en-us/library/system.web.profile.profilemanager.getallprofiles.aspx