How SharePoint simulates users

Source: Internet
Author: User
Try {spsecurity. runwithelevatedprivileges (delegate () // use this method to simulate the Administrator account to run this event handler {spweb web = spcontext. current. web; // at this time, the user is SharePoint \ system // response. write ("User:" + web. currentuser); web. allowunsafeupdates = true; // get the token spuser user = web of the user to be simulated. ensureuser ("veekee \ user1"); spusertoken token = user. usertoken; // use the User Token to construct a new site object spsite sitewithuser = new spsite (web. URL, token); spweb webwidthuser = sitewithuser. rootweb; // at this time, the user is veekee \ user1 // response. write ("User:" + webwidthuser. currentuser); webwidthuser. allowunsafeupdates = true; // use veekee \ user1 to add record splist list = webwidthuser. lists ["test1"]; splistitem item = List. additem (); item ["title"] = "11"; item. update (); webwidthuser. dispose (); sitewithuser. dispose (); web. dispose () ;});} catch (exception ex) {Throw ex ;}

Related information

Code used to simulate a specified user identity in SharePoint: String siteurl = "http: // ecpe-Dev: 82/sites/SJS "; // obtain the token of a user as an administrator. // spsecurity should be used. runwithelevatedprivilege to improve permissions. spsite site = new spsite (siteurl); // the user is SharePoint \ system response. write (site. rootweb. currentuser); // get the token spuser = site of the user to be simulated. rootweb. siteusers ["saicmotorlab \ user1"]; // use the User Token to construct a new site object spsite sitewithuser = new spsite (siteurl, user. use Rtoken); spweb webwithuser = sitewithuser. rootweb; // at this time, the user is saicmotorlab \ user1 response. write (webwithuser. currentuser); splist listwithuser = webwithuser. lists ["simelist"]; // The code above other code can be used when you need to use specified user permissions, such as writing a web service, return the listitem to be viewed based on the input user name.

 

How SharePoint simulates users

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.