CodeAccessPermission.Demand CodeAccessPermission.Demand CodeAccessPermission.Demand CodeAccessPermission.Demand Method

定义

如果未给调用堆栈中处于较高位置的所有调用方授予当前实例所指定的权限,则在运行时强制 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.

public:
 void Demand();
[System.Diagnostics.Conditional("FEATURE_MONO_CAS")]
public void Demand ();
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.

适用于