1

I've currently written a proof of concept console application to add a single user to our user profile service, using the SharePoint web services

http://sharepoint/_vti_bin/userprofileservice.asmx.

I have found that reading in a user can use my default network credentials, however the only way I can update or create a user, I have to use the farm system account.

When using the SharePoint dll's (instead of the webservice). I found that all I had to do was ensure my User Profile service had the same permissions as the user running my application. However changing the User Profile service permissions for the web service doesn't make a slightest bit of difference.

I don't wish to hard code (or put in app.config) the username and password of our farm account, I don't mind using a less privedge account, but using a less privedge account how do I give them access so that the web service works?

My code, (if it helps anyone out) is below. Thanks.

private static UserProfileWS.PropertyData[] CreateUserProfile(string accountName)
        {
            UserProfileWS.PropertyData[] property = null;
            try
            {
                var url = Properties.Settings.Default.UserProfileWSImport_UserProfileWS_UserProfileService;
                var myService = new UserProfileWS.UserProfileService();
                NetworkCredential nc = new NetworkCredential();
                nc.Domain = Properties.Settings.Default.Domain;
                nc.UserName = Properties.Settings.Default.UserName;
                nc.Password = Properties.Settings.Default.Password;

                myService.PreAuthenticate = false;
                myService.Credentials = nc;
                myService.Url = url;

                //If I use either of the lines below instead of NetworkCredentials I get a access denied error when running myservice.CreateUserProfileByAccountName(accountName)
                // myService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials; 
                //myService.UseDefaultCredentials = true;

                property = myService.CreateUserProfileByAccountName(accountName);

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return property;

        }
2

Found the answer after a bit more searching.

To set the Manage Profiles permissions do as follows:

1.Go to Central Admin

2.Choose Application Management > Manage Service Applications

3.Select the User Profile Service Application (do not click the link)

4.Click Administrators in the ribbon

5.Add the user and set the Manage Profiles permission for it

6.Click OK

7.Your done!

  • You made my day! Thank you for using ASMX and NetworkCredentials - I work from outside the domain of the sharepoint and OOTB there is only the network service build in configured as an admin for profile management service (sound a bit weird - all this security and after all network service can create users?). Regards, Michael – user13937 Jan 7 '13 at 14:22
  • Awesome Sauce! I wish I saw this hours ago. – David Jenkins Jul 24 '14 at 20:31
  • @Cann0nF0dder Do you know how to fix this for SharePoint 2007? – Webfort Mar 5 '17 at 16:03
  • @Webfort sorry it's been years since I've worked on a SharePoint 2007 farm. I also have no access to one to try and figure it out. – Cann0nF0dder Mar 9 '17 at 16:28
  • No worries, figured it out in the end. Thanks for getting back to me – Webfort Mar 9 '17 at 16:29

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.