CodeAccessPermission.Demand 方法


如果未对调用堆栈中处于较高位置的所有调用方授予当前实例所指定的权限,则在运行时强制 SecurityExceptionForces a SecurityException at run time if all callers higher in the call stack have not been granted the permission specified by the current instance.

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




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

-or- 调用堆栈中处于较高位置的调用方已经对当前权限对象调用了 Deny()A caller higher 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. 调用堆栈通常表示为向下增长,因此调用堆栈中较高位置的方法调用堆栈中较低的调用方法。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.


不能重写此方法。You cannot override this method.