共用方式為


SPSecurity.CodeToRunElevated Delegate

Represents methods that are passed to RunWithElevatedPrivileges, so that the methods can run with Full Control privileges even if the current user does not otherwise have Full Control.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

Public Delegate Sub CodeToRunElevated

Dim instance As New CodeToRunElevated(AddressOf HandlerMethod)
public delegate void CodeToRunElevated()

Examples

In this example, GetSitesAndGroups is a method without parameters that returns void and is defined somewhere that is accessible to the Button1_Click method.

[C#]

protected void Button1_Click(object sender, EventArgs e)
{
   SPSecurity.CodeToRunElevated elevatedGetSitesAndGroups = new SPSecurity.CodeToRunElevated(GetSitesAndGroups);
   SPSecurity.RunWithElevatedPrivileges(elevatedGetSitesAndGroups);
}

See Also

Reference

Microsoft.SharePoint Namespace

Other Resources

Elevation of Privilege