Record a method for improving running permissions in SharePoint code

Source: Internet
Author: User

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

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.