IStackWalk.Demand 方法


在运行时确定调用堆栈中的所有调用方是否已被授予当前权限对象所指定的权限。Determines at run time whether all callers in the call stack have been granted the permission specified by the current permission object.

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


调用堆栈中处于较高位置的调用方不具有当前权限对象所指定的权限。A caller higher in the call stack does not have the permission specified by the current permission object.

- 或 --or- 调用堆栈中的调用方已经对当前权限对象调用了 Deny()A caller in the call stack has called Deny() on the current permission object.


此方法通常由安全库用于确保调用方有权访问资源。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.

不检查调用此方法的代码的权限;该检查从该代码的直接调用方开始,并沿堆栈向上进行。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. Demand 仅当未 SecurityException 引发时才成功。Demand succeeds only if no SecurityException is raised.