PermissionSet.PermitOnly 方法

定義

會讓透過非目前 PermissionSet 子集的任何 PermissionSet 呼叫程式碼傳遞之任何 Demand() 失敗。Causes any Demand() that passes through the calling code for any PermissionSet that is not a subset of the current PermissionSet to fail.

public:
 virtual void PermitOnly();
public void PermitOnly ();
public virtual void PermitOnly ();
abstract member PermitOnly : unit -> unit
override this.PermitOnly : unit -> unit
Public Sub PermitOnly ()
Public Overridable Sub PermitOnly ()

實作

備註

PermitOnly 類似于 Deny ,在這兩種情況下,堆疊會在其他情況成功時失敗。PermitOnly is similar to Deny, in that both cause stack walks to fail when they would otherwise succeed. 不同之處在于,會 Deny 指定將導致堆疊失敗的許可權,但 PermitOnly 指定的許可權不會導致堆疊逐步失敗。The difference is that Deny specifies permissions that will cause the stack walk to fail, but PermitOnly specifies the only permissions that do not cause the stack walk to fail. 呼叫這個方法,以確保您的程式碼只能用來存取指定的資源。Call this method to ensure that your code can be used to access only the specified resources.

PermitOnly 因為許可權的需求無法成功,所以會忽略未授與的許可權。PermitOnly is ignored for a permission not granted because a demand for that permission cannot succeed. 但是,如果在呼叫堆疊中較低的程式碼在稍後呼叫 Demand 該許可權, SecurityException 當堆疊逐步到達嘗試呼叫的程式碼時,就會擲回 PermitOnlyHowever, if code lower on the call stack later calls Demand for that permission, a SecurityException is thrown when the stack walk reaches the code that tried to call PermitOnly. 這是因為呼叫的程式碼 PermitOnly 沒有被授與許可權,即使是 PermitOnly 針對該許可權呼叫也一樣。This is because the code that called PermitOnly has not been granted the permission, even though it called PermitOnly for that permission. 呼叫堆疊通常會顯示為不斷增加,讓呼叫堆疊中較高的方法在呼叫堆疊中較低的呼叫方法。The call stack is typically represented as growing down, so that methods higher in the call stack call methods lower in the call stack.

適用於