2

I am developing a webpart in SharePoint 2013 that must access the user profiles of users in the Active Directory. The problem is that when I try to access some user profile properties I get an "Unauthorized Exception" because my user is not the administrator.

My first guess is to add Everyone with read permissions in the User Profile Service Application in the CA but there is only Full Control Permissions option

enter image description here

Any other idea?

3
  • 1
    why don't use elevated privileges and give read permissions or whatever permissions you required to application pool account, not sure if that's the best practice though. Commented Jun 19, 2013 at 20:53
  • I had already tried runwith elevated privileges but didn't work. Anything else I should try? Thank you very much Commented Jun 20, 2013 at 8:11
  • 1
    Have you tried using the the CSOM or REST APIs instead? Commented Jun 20, 2013 at 16:54

1 Answer 1

1

If you use a WebPart i conclude that you are using server side code. If thats right you can use elevated privileges to access the user profiles. BTW when you using elevated privileges your code runs under the user that is specified in your WebApplication's AppPool which is quite sure a System Account.

SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            SPSite site = new SPSite(http://server);
            SPWeb myweb = site.OpenWeb();
            SPUser found = myweb.AllUsers.GetByID(1);
        });
1
  • Thank you for your amswer. I think I found the solution. I gave Retrieve people data for search crawlers to Everyone account. I will try this. Thank you again Commented Jun 20, 2013 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.