Share via


PermissionSet.Demand 方法

定义

如果未对调用堆栈中所有较高级的调用方授予当前实例所指定的权限,则在运行时强制 SecurityException

public:
 virtual void Demand();
public void Demand ();
public virtual void Demand ();
abstract member Demand : unit -> unit
override this.Demand : unit -> unit
Public Sub Demand ()
Public Overridable Sub Demand ()

实现

例外

调用链中的调用方没有所需的权限。

示例

下面的代码示例演示如何使用 Demand 方法要求权限集中的所有权限。 此代码示例是为 PermissionSet 类提供的一个更大示例的一部分。

// Demand all the permissions in the set.
Console::WriteLine( "Demand all permissions." );
ps1->Demand();
// Demand all the permissions in the set.
Console.WriteLine("Demand all permissions.");
ps1.Demand();
' Demand all the permissions in the set.
Console.WriteLine("Demand all permissions.")
ps1.Demand()

注解

PermissionSet 使用 Demand 可确保所有调用方都通过一个操作拥有集中的所有权限。

不检查调用此方法的代码的权限;检查从该代码的直接调用方开始,然后继续堆栈。 调用堆栈通常表示为向下增长,因此调用堆栈中较高方法调用调用堆栈中较低的方法。 Demand 仅当未引发时 SecurityException ,才会成功。

PermissionSet如果 包含不继承自 CodeAccessPermission的权限,则Demand还会调用这些权限的方法。

适用于