CodeAccessPermission.Demand CodeAccessPermission.Demand CodeAccessPermission.Demand CodeAccessPermission.Demand Method

定義

如果呼叫堆疊中所有較高層的呼叫端尚未授與目前執行個體 (Instance) 所指定的使用權限,請於執行階段強制執行 SecurityExceptionForces a SecurityException at run time if all callers higher in the call stack have not been granted the permission specified by the current instance.

public:
 virtual void Demand();
[System.Diagnostics.Conditional("FEATURE_MONO_CAS")]
public void Demand ();
abstract member Demand : unit -> unit
override this.Demand : unit -> unit
Public Sub Demand ()

實作

例外狀況

呼叫堆疊中較高層的呼叫端未授與目前執行個體所指定的使用權限。A caller higher in the call stack does not have the permission specified by the current instance.

-或--or- 呼叫堆疊中較高層的呼叫端已經呼叫目前使用權限物件上的 Deny()A caller higher in the call stack has called Deny() on the current permission object.

備註

安全程式庫通常會使用這個方法以確保呼叫端擁有存取資源的權限。This method is typically used by secure libraries to ensure that callers have permission to access a resource. 安全類別庫中的檔案類別的呼叫,例如Demand的必要FileIOPermission之前執行檔案作業要求的呼叫端。For example, a file class in a secure class library calls Demand for the necessary FileIOPermission before performing a file operation requested by the caller.

呼叫這個方法的程式碼的權限就不會檢查;檢查立即呼叫端程式碼從開始,並繼續向上堆疊。The permissions of the code that calls this method are not examined; the check begins from the immediate caller of that code and proceeds up the stack. 通常,向下成長,來表示呼叫堆疊,使方法呼叫堆疊中較高層呼叫方法較低的呼叫堆疊中。The call stack is typically represented as growing down, so that methods higher in the call stack call methods lower in the call stack. Demand 只有當沒有成功SecurityException,就會引發。Demand succeeds only if no SecurityException is raised.

給繼承者的注意事項

您無法覆寫這個方法。You cannot override this method.

適用於