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?

  • 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. – Muhammad Raja Jun 19 '13 at 20:53
  • I had already tried runwith elevated privileges but didn't work. Anything else I should try? Thank you very much – Alvmad Jun 20 '13 at 8:11
  • 1
    Have you tried using the the CSOM or REST APIs instead? – Matthew McDermott Jun 20 '13 at 16:54
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);
        });
| improve this answer | |
  • 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 – Alvmad Jun 20 '13 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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