IPermission.Demand 方法

定义

如果不满足安全要求,则会在运行时引发 SecurityExceptionThrows a SecurityException at run time if the security requirement is not met.

public:
 void Demand();
public void Demand ();
abstract member Demand : unit -> unit
Public Sub Demand ()

注解

此方法通常由安全库用于确保调用方有权访问资源。This method is typically used by secure libraries to ensure that callers have permission to access a resource. 例如,在 Demand FileIOPermission 执行调用方请求的文件操作之前,安全类库中的文件类会调用所需的。For example, a file class in a secure class library calls Demand for the necessary FileIOPermission before performing a file operation requested by the caller.

虽然实现此接口方法的大多数类都通过执行完整堆栈遍历来满足安全条件,但并不一定要执行堆栈遍历。Although the majority of the classes that implement this interface method satisfy the security criteria by performing a full stack walk, a stack walk is not necessarily performed. 不执行堆栈审核的实现的一个示例是 PrincipalPermission.DemandAn example of an implementation that does not perform a stack walk is PrincipalPermission.Demand.

执行堆栈审核时,不会检查调用此方法的代码的权限;该检查从该代码的直接调用方开始,并沿堆栈向上进行。When a stack walk is performed, the permissions of the code that calls this method are not examined; the check begins from the immediate caller of that code and proceeds up the stack. 调用堆栈通常表示为向下增长,因此调用堆栈中较高位置的方法调用堆栈中较低的调用方法。The call stack is typically represented as growing down, so that methods higher in the call stack call methods lower in the call stack. Demand 仅当未 SecurityException 引发时才成功。Demand succeeds only if no SecurityException is raised.

适用于