2

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?

4

3 回答 3

2

There is a ProfileManager with the a method GetAllProfiles():

http://msdn.microsoft.com/en-us/library/system.web.profile.profilemanager.getallprofiles.aspx

于 2009-09-10T11:06:42.973 回答
2

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

看看http://chiragrdarji.blogspot.com/2007/03/impersonation-using-code.html,这个章节似乎通过使用System.Security.Principal.WindowsIdentityclass 和System.Security.Principal.WindowsImpersonationContext. 可能值得一试。

于 2009-09-10T10:09:33.220 回答
1
ProfileInfoCollection profiles = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All);
foreach (ProfileInfo pi in profiles)
{
    ProfileCommon p = Profile.GetProfile(pi.UserName);
    countries.Add(p.Country);        
}
于 2011-12-30T11:11:50.013 回答