IStackWalk.Demand 方法

定義

判斷執行階段期間呼叫堆疊中的所有呼叫端,是否已獲得目前權限物件所指定的權限。Determines at run time whether all callers in the call stack have been granted the permission specified by the current permission object.

public:
 void Demand();
public void Demand ();
abstract member Demand : unit -> unit
Public Sub Demand ()

例外狀況

此呼叫堆疊中較高層的呼叫端,不需要獲得目前權限物件所指定的權限。A caller higher in the call stack does not have the permission specified by the current permission object.

-或--or- 此呼叫堆疊中的呼叫端已呼叫目前權限物件上的 Deny()A caller 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 執行呼叫端要求的檔案作業之前,安全類別庫中的檔案類別會呼叫必要的 FileIOPermissionFor 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. Demand 只有在未 SecurityException 引發時,才會成功。Demand succeeds only if no SecurityException is raised.

適用於