IStackWalk.Assert IStackWalk.Assert IStackWalk.Assert IStackWalk.Assert Method

定義

即使堆疊中較高層的呼叫端尚未授與存取資源的使用權限,仍會判斷提示 (Assert) 呼叫的程式碼可存取目前的使用權限物件所識別的資源。Asserts that the calling code can access the resource identified by the current permission object, even if callers higher in the stack have not been granted permission to access the resource.

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

例外狀況

呼叫的程式碼沒有 AssertionThe calling code does not have Assertion.

備註

呼叫Assert呼叫堆疊中較高層的呼叫端的權限檢查就會停止。Calling Assert stops the permission check on callers higher in the call stack. 因此,即使這些呼叫端沒有必要的權限,他們仍然可以存取資源。Therefore, even if these callers do not have the requisite permissions, they can still access resources. 判斷提示是有效的程式碼呼叫時,才Assert通過安全性檢查,它會判斷提示之權限。An assertion is effective only if the code that calls Assert passes the security check for the permission that it is asserting.

呼叫Assert會生效,直到呼叫程式碼傳回給其呼叫端,或直到後續呼叫Assert轉譯先前的判斷提示無效。A call to Assert is effective until the calling code returns to its caller or until a subsequent call to Assert renders the previous assertion ineffective. 此外,RevertAssert或是RevertAll移除暫止AssertAlso, RevertAssert or RevertAll removes a pending Assert.

Assert 會忽略該權限的要求將會失敗,因為未授與權限。Assert is ignored for a permission not granted because a demand for that permission will not succeed. 不過,如果在呼叫堆疊中較低的程式碼會呼叫Demand該權限,請SecurityException堆疊查核行程達到嘗試呼叫的程式碼時,會擲回AssertHowever, if code lower on the call stack calls Demand for that permission, a SecurityException is thrown when the stack walk reaches the code that tried to call Assert. 這是因為,所呼叫的程式碼Assert沒有被授予權限,即使應用程式嘗試Assert它。This happens because the code that called Assert has not been granted the permission, even though it tried to Assert it.

警告

因為呼叫Assert移除所有程式碼呼叫鏈結中的需求必須被授與權限來存取指定的資源,如果不正確或不當使用,它可以開啟啟動安全性弱點。Because calling Assert removes the requirement that all code in the call chain must be granted permission to access the specified resource, it can open up security vulnerabilities if used incorrectly or inappropriately. 因此,它應該使用小心謹慎。Therefore, it should be used with great caution.

適用於

另請參閱