CodeAccessPermission.Deny 方法

定义

注意

此 API 现已过时。

注意

Deny is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.

防止处于调用堆栈较高位置的调用函数使用可以调用此方法来访问当前实例指定资源的代码。Prevents callers higher in the call stack from using the code that calls this method to access the resource specified by the current instance.

public:
 virtual void Deny();
public:
 void Deny();
[System.Obsolete]
public void Deny ();
public void Deny ();
[System.Obsolete("Deny is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public void Deny ();
[System.Diagnostics.Conditional("FEATURE_MONO_CAS")]
public void Deny ();
[<System.Obsolete>]
abstract member Deny : unit -> unit
override this.Deny : unit -> unit
abstract member Deny : unit -> unit
override this.Deny : unit -> unit
[<System.Obsolete("Deny is obsolete and will be removed in a future release of the .NET Framework. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>]
abstract member Deny : unit -> unit
override this.Deny : unit -> unit
[<System.Diagnostics.Conditional("FEATURE_MONO_CAS")>]
member this.Deny : unit -> unit
Public Sub Deny ()

实现

属性

例外

已存在一个用于当前帧的活动的 Deny()There is already an active Deny() for the current frame.

注解

重要

Deny 方法应仅用于防止完全受信任的代码意外访问资源。The Deny method should be used only to protect resources from accidental access by fully trusted code. 不应使用它来防止不受信任的代码有意滥用资源。It should not be used to protect resources from intentional misuse by untrusted code. 例如,如果方法发出权限的,然后 A Deny 调用方法 B ,则方法 B 可以通过发出来 overtly 重写 Deny AssertFor example, if method A issues a Deny for a permission and then calls method B, method B can overtly override the Deny by issuing an Assert. 调用的方法在堆栈中始终更高。The called method is always higher in the stack. 因此,如果方法 B 尝试访问受保护的资源,则安全系统会开始检查其权限,因为方法 B 是直接调用方,然后向下遍历堆栈以确认 Deny PermitOnly 堆栈中没有或更低。Therefore, if method B tries to access a protected resource, the security system begins checking for permissions with it because method B is the immediate caller, and then walks down the stack to confirm that there is no Deny or PermitOnly lower in the stack. B尝试访问资源的方法可以使用方法立即停止堆栈遍历 AssertMethod B, which is trying to access the resource, can stop the stack walk immediately by using the Assert method. 在这种情况下, Deny A 从不会发现 (调用方法) 放置在堆栈上。In that case, the Deny placed on the stack by method A (the calling method) is never discovered.

此方法阻止调用堆栈中较高位置的调用方通过调用此方法的代码访问受保护的资源,即使这些调用方已被授予访问该方法的权限。This method prevents callers higher in the call stack from accessing the protected resource through the code that calls this method, even if those callers have been granted permission to access it. 调用堆栈通常表示为向下增长,因此调用堆栈中较高位置的方法调用堆栈中较低的调用方法。The call stack is typically represented as growing down, so that methods higher in the call stack call methods lower in the call stack.

Deny 可以限制程序员的责任,或帮助防止意外的安全问题,因为它有助于防止调用的方法 Deny 访问由拒绝的权限保护的资源。Deny can limit the liability of the programmer or help prevent accidental security issues because it helps prevent the method that calls Deny from being used to access the resource protected by the denied permission. 如果方法对 Deny 权限进行调用,并且 Demand 调用堆栈中的调用方调用了某个权限,则该安全检查到达时将失败 DenyIf a method calls Deny on a permission, and if a Demand for that permission is invoked by a caller lower in the call stack, that security check will fail when it reaches the Deny.

Deny 调用代码返回到其调用方之前,对的调用将有效。The call to Deny is effective until the calling code returns to its caller. 帧上只能有一个 Deny 处于活动状态。Only one Deny can be active on a frame. Deny如果在帧上存在活动时尝试调用,则会 Deny 生成一个 SecurityExceptionAn attempt to call Deny when an active Deny exists on the frame results in a SecurityException. 调用 RevertDenyRevertAll 删除活动 DenyCall RevertDeny or RevertAll to remove an active Deny. Deny 对于未授予的权限,将忽略,因为对该权限的请求将不会成功。Deny is ignored for a permission not granted because a demand for that permission will not succeed.

继承者说明

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

适用于