IStackWalk.PermitOnly 方法

定义

导致所有对象的每个 Demand()(除了通过调用代码的当前一个)失败,即使调用堆栈中较高级别的代码已被授予访问其他资源的权限。Causes every Demand() for all objects except the current one that passes through the calling code to fail, even if code higher in the call stack has been granted permission to access other resources.

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

注解

PermitOnly 类似于 Deny ,在这两个情况下,堆栈遍历将会失败,否则将会成功。PermitOnly is similar to Deny, in that both cause stack walks to fail when they would otherwise succeed. 不同之处在于 Deny 指定将导致堆栈遍历失败的权限,但 PermitOnly 指定不会导致堆栈遍历失败的唯一权限。The difference is that Deny specifies permissions that will cause the stack walk to fail, but PermitOnly specifies the only permissions that do not cause the stack walk to fail. 调用此方法以确保你的代码只能用于访问指定的资源。Call this method to ensure that your code can be used to access only the specified resources.

PermitOnly 对于未授予的权限,将忽略,因为对该权限的请求将不会成功。PermitOnly is ignored for a permission not granted because a demand for that permission will not succeed. 但是,如果调用堆栈上较低的代码以后调用 Demand 了该权限,则 SecurityException 当堆栈遍历到达尝试调用的代码时,将引发 PermitOnlyHowever, if code lower on the call stack later calls Demand for that permission, a SecurityException is thrown when the stack walk reaches the code that tried to call PermitOnly. 这是因为调用的代码 PermitOnly 没有获得权限,即使它是 PermitOnly 为该权限调用的。This is because the code that called PermitOnly has not been granted the permission, even though it called PermitOnly for that permission. 调用堆栈通常表示为向下增长,因此调用堆栈中较高位置的方法调用堆栈中较低的调用方法。The call stack is typically represented as growing down, so that methods higher in the call stack call methods lower in the call stack.

适用于