CodeAccessPermission.Demand 方法


如果在呼叫堆疊中較高的所有呼叫端都尚未被授與由目前執行個體所指定之權限,則會在執行階段強制執行 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.

 virtual void Demand();
 void Demand();
public void Demand ();
public void Demand ();
abstract member Demand : unit -> unit
override this.Demand : unit -> unit
member 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 執行呼叫端要求的檔案作業之前,安全類別庫中的檔案類別會呼叫必要的 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. 呼叫堆疊通常會顯示為不斷增加,讓呼叫堆疊中較高的方法在呼叫堆疊中較低的呼叫方法。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.