Method:Spsecurity. runwithelevatedprivileges
Namespace:Microsoft. SharePoint
ProgramSet:Microsoft. SharePoint (in Microsoft. Sharepoint. dll)
Usage:
Spsecurity. runwithelevatedprivileges (Delegate(){Using(Spsite site =NewSpsite (Web. Site. ID )){// Implementation Details omitted}});
Note:
You mustInternalCreate a new spsite object.SpsiteObject, even if you reference it within delegate, it still does not have full control permissions. UseUsingKeyword to ensure that the spsite object is parsed within the delegate.
In addition, this method promotes the current account to the application pool account of IIS, that is, the Administrator account of the Web application, so as to obtain full control permissions.
There are more detailed examples of the original source.
Supplement
========
What is the difference between this method and impersonate of ASP. NET?
Well, the latter either needs to change web. config orCodeThe username and password you want to use in hard code. Compared with the method provided by the SharePoint object model, the disadvantage is obvious. So in Sharepoint, use om.
From:
Http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx
This page is specific to the 2007 product release