2

We are using sp2013.

There is a custom user profile property with name: MyProperty (boolean).

The property cannot be edited by user.

I want to update the property value for current user on an application page on click of a button.

Since the property cannot be edited by user, should RWEP?

2 Answers 2

1

An easier approach is to allow the user to update the property and just hide the value from their edit page. Then you don't need RWEP. Just a thought.

2
  • Yes I have gone ahead with this method.
    – variable
    Commented Apr 11, 2014 at 10:53
  • Can I get an answer click from you? Commented Apr 12, 2014 at 13:00
2

Run with Elevated privileges runs the Code in System Account/App pool account. So you will have to make sure that App pool account has "Manage Profile Permission" rights to the User Profile Service. Follow below steps: Go to Central Admin-->Choose Application Management --> Manage Service Applications--> Select the User Profile Service Application (do not open the service application). Click Administrators in the ribbon on top -->Add the App pool account and set the Manage Profiles permission. See this blog for Granting permission to UPS.

 SPSecurity.RunWithElevatedPrivileges(delegate()
       {
        using (SPSite site = new SPSite("http://servername"))//change the hardcoded URL to suit your requirement
        {
            SPServiceContext serviceContext = SPServiceContext.GetContext(site);
            UserProfileManager userProfileMgr = new UserProfileManager(serviceContext);
            UserProfile user = userProfileMgr.GetUserProfile(@'domain\username');
            user["propertyName"]  = "newValue";
            user.Commit();


        }
    });

See this MSDN Blog for Working with UPS using Server Object Model.

16
  • Can you provide some code
    – variable
    Commented Apr 10, 2014 at 17:00
  • @variable edited my answer
    – Unnie
    Commented Apr 10, 2014 at 18:06
  • The system acc has full control, that is what RWEP does right? Then why do I have to set the right to apppool acc.?
    – variable
    Commented Apr 11, 2014 at 2:57
  • also suppose I do not use RWEP. Then which user do I give rights to?
    – variable
    Commented Apr 11, 2014 at 3:04
  • App pool account is the site col admin or the web app admin?
    – variable
    Commented Apr 11, 2014 at 3:51

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.