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()

備註

重要

Deny方法應該只用來保護資源不受完全信任程式碼意外存取。 它不應該用來防止資源遭到不受信任的程式代碼刻意誤用。 例如,如果方法A發出許可權的 ,然後呼叫 方法 B,方法B可以發出 Assert來覆寫 DenyDeny 。 呼叫的方法在堆疊中一律較高。 因此,如果方法 B 嘗試存取受保護的資源,則安全性系統會開始檢查其許可權,因為方法 B 是立即呼叫者,然後逐步執行堆疊以確認堆疊中沒有 DenyPermitOnly 更低。 嘗試存取資源的方法 B,可以使用 方法立即 Assert 停止堆疊逐步執行。 在此情況下, Deny 永遠不會探索呼叫 A 方法) 方法 (堆疊上放置的 。

這個方法可防止呼叫堆疊中的呼叫端透過呼叫此方法的程式代碼存取受保護的資源,即使這些呼叫端已獲授與存取它的許可權也一樣。 呼叫堆疊通常表示為相應減少,因此呼叫堆棧呼叫方法中的方法會降低呼叫堆疊。

Deny 可以限制程式設計人員的責任,或協助防止意外的安全性問題,因為它有助於防止呼叫 Deny 的方法用來存取受拒絕許可權保護的資源。 如果方法在許可權上呼叫 Deny ,而且如果 Demand 呼叫堆疊中較低的呼叫端叫用該許可權的 ,當到達 Deny時,該安全性檢查將會失敗。

的呼叫 Deny 會生效,直到呼叫程式代碼傳回其呼叫端為止。 畫面上只能有一個 Deny 作用中。 試著在畫面上存在作用中時Deny呼叫 Deny ,會導致 SecurityException。 呼叫 RevertDenyRevertAll 以移除使用中的 DenyDeny 對於未授與的許可權,會忽略 ,因為該許可權的需求將不會成功。

給繼承者的注意事項

您無法覆寫這個方法。

適用於