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.

阻止调用堆栈中的调用方使用调用此方法的代码来访问当前实例指定的资源。

public:
 virtual 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.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
Public Sub Deny ()

实现

属性

例外

当前帧已 Deny() 处于活动状态。

注解

Important

Deny该方法应仅用于保护资源免受完全信任代码意外访问。 它不应用于防止资源被不受信任的代码故意滥用。 例如,如果方法A发出Deny权限,然后调用方法B,则方法B可以通过发出一个Deny来公开重写Assert该方法。 调用的方法在堆栈中始终较高。 因此,如果方法 B 尝试访问受保护的资源,则安全系统开始检查其权限,因为方法是 B 直接调用方,然后向下走堆栈以确认堆栈中没有 DenyPermitOnly 更低。 尝试访问资源的方法 B可以使用该方法 Assert 立即停止堆栈演练。 在这种情况下, Deny 永远不会发现按方法(调用方法 A )放置在堆栈上。

此方法可防止调用堆栈中较高级别的调用方通过调用此方法的代码访问受保护资源,即使这些调用方已获得访问它的权限。 调用堆栈通常表示为向下增长,因此调用堆栈调用方法中的方法越低。

Deny 可以限制程序员的责任或帮助防止意外的安全问题,因为它有助于防止调用 Deny 的方法用于访问受拒绝权限保护的资源。 如果方法调用 Deny 权限,并且 Demand 调用堆栈中较低调用方调用该权限,则到达 Deny该权限时,该安全检查将失败。

调用生效 Deny ,直到调用代码返回到其调用方。 帧上只能有一个 Deny 活动。 当帧上存在活动Deny时,尝试调用Deny结果为 SecurityException. 调用或删除RevertDeny活动RevertAllDenyDeny 对于未授予的权限,将忽略 ,因为对该权限的需求不会成功。

继承者说明

不能重写此方法。

适用于