The SPSecurity class provides a static method called “RunWithElevatedPrivileges” that executes the code with Full Control rights under the identity of SHAREPOINT\system even if the user does not have Full Rights. This method should be used with caution and should not expose direct access to system resources or retrieve sensitive and secure data that the user does not have privilege to. This method can, however, be used for simpler actions like retrieving all the names of the sites or displaying read-only data that needs to be performed on behalf of the system.
Code example:
SPSite nonelevSiteCollection = SPContext.Current.Site; SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite oSiteCollection = new SPSite(nonelevSiteCollection.ID)) { SPWebCollection collWebsites = oSiteCollection.AllWebs; ///rest of the code goes here } });
ReTweet this Tip!
Posted
Sep 08 2010, 08:00 AM
by
sos