Improve code running permissions to simulate administrator identity

Source: Internet
Author: User
Tags silverlight

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

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.