Domanda

Stiamo usando SP2013.

C'è una proprietà del profilo utente personalizzato con nome: MyProperty (Boolean).

La proprietà non può essere modificata dall'utente.

Voglio aggiornare il valore della proprietà per l'utente corrente su una pagina dell'applicazione sul clic di un pulsante.

Poiché la proprietà non può essere modificata dall'utente, dovrebbe rwep?

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top