Moss2007Improve code running permissions to simulate administrator identity
Note: The Code in delegate () {} must re-initialize the corresponding object SPSite and SPWeb. In this case, even if the code runs within the range of privilege escalation, the administrator can log on to the account.
SPSecurity. RunWithElevatedPrivileges (delegate (){
// The code displayed here is the code to be run when the permission is upgraded.
// This code snippet runs under the SHAREPOINT/SYSTEM account.
});
// Example
SPSecurity. RunWithElevatedPrivileges (
Delegate ()
{
Using (SPSite ElevatedsiteColl = new SPSite ("http: // xxxx: xx") // obtain spsite;
{
Using (SPWeb ElevatedSite = ElevatedsiteColl. OpenWeb () // get spweb;
{
String SiteCollectionOwner = ElevatedsiteColl. Owner. Name;
String Visits = ElevatedsiteColl. Usage. Visits. ToString ();
String RootAuditEntries = ElevatedSite. RootFolder. Audit. GetEntries (). Count. ToString ();
}
}
});
In the Sharepoint 2010 client object model, the permission method is also added, but it is said that it is not used in silverlight. If anyone knows how to improve the permission in SilverLight, please let us know. Thank you very much!
ClientContext client = new ClientContext("Site Url");
Client. Credentials = new System. Net. NetworkCredential ([user name], [Password], [domain name]);
///do everything with full control