CodeAccessPermission.Deny CodeAccessPermission.Deny CodeAccessPermission.Deny CodeAccessPermission.Deny Method

定義

警告

此 API 現已淘汰。

防止呼叫堆疊中較高層的呼叫端,使用呼叫這個方法的程式碼來存取目前執行個體所指定的資源。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();
[System.Obsolete]
[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.")]
[System.Diagnostics.Conditional("FEATURE_MONO_CAS")]
public void Deny ();
abstract member Deny : unit -> unit
override 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,方法Bovertly 可以覆寫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是立即呼叫端,上下然後會逐步引導的堆疊,以確認沒有任何DenyPermitOnly堆疊中較低。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,這嘗試存取資源,可以停止堆疊查核行程立即使用Assert方法。Method 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. 呼叫RevertDeny或是RevertAll若要移除作用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.

適用於