ProfileProvider: get a list of all profiles

I am developing an asp.net intranet site using ActiveDirectoryMembershipProvider and SqlProfileProvider.

One of the requirements on my website is a Birthday page, which will require me to list all profiles and get birthday information.

I approached the problem as follows:

  • Calling the static method Membership.GetAllUsers ();
  • Iterate through the list of users and extract the profile from the member username

This approach, however, failed for the following reasons:

  • The webapp impersonates the currently logged in user to get its AD credentials (impersonate = "true" identity in the web.config file), so I get an "access denied" exception when I try to call GetAllUsers
  • If I try to force the webapp to impersonate the superuser account then AD returns the usernames as username @ domain-name, but in my profile provider they were originally stored as domainname \ username.

So how would you get around this problem to get the entire list of profiles for any member of the organization?

+2


source to share


3 answers


There is ProfileManager with GetAllProfiles () method:



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

+2


source


Although I've never done this before, you could try to create a secondary impersonation context that, when set, will invoke GetAllUsers

.



Have a look at http://chiragrdarji.blogspot.com/2007/03/impersonation-using-code.html , this guy seems to have achieved a change in security context using the class System.Security.Principal.WindowsIdentity

as well System.Security.Principal.WindowsImpersonationContext

. It might be worth checking out.

+2


source


ProfileInfoCollection profiles = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All);
foreach (ProfileInfo pi in profiles)
{
    ProfileCommon p = Profile.GetProfile(pi.UserName);
    countries.Add(p.Country);        
}

      

+1


source







All Articles