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 移除使用 Deny 中。Call 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.

適用於