IStackWalk.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. 另外, RevertAssertRevertAll 删除挂起的 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 未被授予权限,即使它尝试了该权限 AssertThis 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.

适用于