Export (0) Print
Expand All

CodeAccessPermission.Deny Method

Prevents callers higher in the call stack from using the code that calls this method to access the resource specified by the current instance.

[Visual Basic]
Public Overridable Sub Deny() Implements IStackWalk.Deny
[C#]
public virtual void Deny();
[C++]
public: virtual void Deny();
[JScript]
public function Deny();

Implements

IStackWalk.Deny

Exceptions

Exception Type Condition
SecurityException There is already an active Deny for the current frame.

Remarks

This method prevents callers higher in the call stack from accessing the protected resource through the code that calls this method, even if those callers have been granted permission to access it. The call stack is typically represented as growing down, so that methods higher in the call stack call methods lower in the call stack.

Deny can limit the liability of the programmer or help prevent accidental security vulnerabilities because it helps prevent the method that calls Deny from being used to access the resource protected by the denied permission. If a method calls Deny on a permission, and if a Demand for that permission is invoked by a caller lower in the call stack, that security check will fail when it reaches the Deny.

The call to Deny is effective until the calling code returns to its caller. Only one Deny can be active on a frame. An attempt to call Deny when an active Deny exists on the frame results in a SecurityException. Call RevertDeny or RevertAll to remove an active Deny. Deny is ignored for a permission not granted because a demand for that permission will not succeed.

Notes to Inheritors:  You cannot override this method.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

CodeAccessPermission Class | CodeAccessPermission Members | System.Security Namespace | Deny | Overriding Security Checks

Show:
© 2015 Microsoft