Tip : SPSecurity.RunWithElevatedPrivileges

While using SPSecurity.RunWithElevatedPrivileges in your code, Always remember to create your own Spweb/Spsite objects and to never use an object created outside the RunWithElevatedPrivileges scope.

using (SPWeb web = SPControl.GetContextWeb(Context))
//Your Code

--- The other way is ---

       Public void ProcessMethod()
            SPSecurity.CodeToRunElevated elevatedMethod = new                           SPSecurity.CodeToRunElevated(CustomMethod);

The code uses a method from SPSecurity to indicate the name of the method that will run with Full permission. Simply pass in the name of the method as the parameter (CustomMethod). In the second line, you execute that method with elevated privileges

No comments:

Post a Comment