Alternate Impersonation Method of RunWithElevatedPrivileges()

Authentication,Permission,Security,Site Collection

This post let you know the alternative impersonation method to RunWithElevatedPrivileges(). We can get the SPUserToken class object to pass as parameter in constructor of SPSite. Code sample is below:


//SPUsertoken object.

SPUserToken spUserToken = SPContext.Current.Site.SystemAccount.UserToken;

//pass spUserToken to SPSite constructor

using(SPSite siteCollection = new SPSite("siteCollectionUrl", spUserToken))


   //write your elevated custom code here



Happy Coding…