System.Security.PermissionSet.PermitOnly Method

Causes any PermissionSet.Demand that passes through the calling code for any System.Security.PermissionSet that is not a subset of the current System.Security.PermissionSet to fail.

Syntax

public void PermitOnly ()

Exceptions

TypeReason
System.Security.SecurityExceptionA previous call to PermitOnly has already set the permissions for the current stack frame.

Remarks

PermissionSet.PermitOnly is similar to PermissionSet.Deny, in that both cause stack walks to fail when they would otherwise succeed. The difference is that PermissionSet.Deny specifies permissions that will cause the stack walk to fail, but PermissionSet.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.

PermissionSet.PermitOnly is ignored for a permission not granted because a demand for that permission cannot succeed. However, if code lower on the call stack later calls PermissionSet.Demand for that permission, a System.Security.SecurityException is thrown when the stack walk reaches the code that tried to call PermissionSet.PermitOnly. This is because the code that called PermissionSet.PermitOnly has not been granted the permission, even though it called PermissionSet.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.

Requirements

Namespace: System.Security
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0