PermissionSet.Assert 方法
定义
声明调用代码能够通过调用此方法的代码,访问受权限请求保护的资源,即使未对堆栈中处于较高位置的调用方授予访问该资源的权限。Declares that the calling code can access the resource protected by a permission demand through the code that calls this method, even if callers higher in the stack have not been granted permission to access the resource. 使用 Assert() 会产生安全漏洞。Using Assert() can create security vulnerabilities.
public:
virtual void Assert();
public void Assert ();
public virtual void Assert ();
abstract member Assert : unit -> unit
override this.Assert : unit -> unit
Public Sub Assert ()
Public Overridable Sub Assert ()
实现
例外
尚未向断言的 PermissionSet 实例授予断言代码。The PermissionSet instance asserted has not been granted to the asserting code.
- 或 --or- 已存在一个用于当前帧的活动的 Assert()。There is already an active Assert() for the current frame.
注解
这是一种在一个帧中同时断言多个权限的唯一方法,因为在一个帧上只能有一个权限 Assert 处于活动状态。This is the only way to assert multiple permissions at the same time within a frame because only one Assert can be active on a frame. Assert 仅对授予的权限有效。Assert is only effective for granted permissions. 调用 CodeAccessPermission.RevertAssert 或 CodeAccessPermission.RevertAll 方法可取消活动 Assert 。Call the CodeAccessPermission.RevertAssert or CodeAccessPermission.RevertAll method to cancel an active Assert.
注意
因为调用 Assert 方法会消除调用链中的所有代码都必须被授予访问指定资源的权限的要求,所以如果使用不当或不当,则可能会打开安全漏洞。Because calling the Assert method 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.