IPermission.Demand IPermission.Demand IPermission.Demand IPermission.Demand Method

定義

如果不符合安全性要求,在 Run Time 時會擲回 SecurityExceptionThrows a SecurityException at run time if the security requirement is not met.

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

備註

安全程式庫通常會使用這個方法以確保呼叫端擁有存取資源的權限。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.

雖然大部分的類別可實作這個介面方法會滿足安全性準則執行完整堆疊查核行程,不一定會執行堆疊查核行程。Although the majority of the classes that implement this interface method satisfy the security criteria by performing a full stack walk, a stack walk is not necessarily performed. 舉例來說,不會執行堆疊查核行程實作PrincipalPermission.DemandAn example of an implementation that does not perform a stack walk is PrincipalPermission.Demand.

執行堆疊查核行程時,就不會檢查呼叫這個方法的程式碼的權限;檢查立即呼叫端程式碼從開始,並繼續向上堆疊。When a stack walk is performed, 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.

適用於