System.Security.Permissions.SecurityPermissionAttribute Class

Allows security actions for System.Security.Permissions.SecurityPermission to be applied to code using declarative security. This class cannot be inherited.

See Also: SecurityPermissionAttribute Members


[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.All, AllowMultiple=true, Inherited=false)]
public sealed class SecurityPermissionAttribute : CodeAccessSecurityAttribute


The scope of the declaration that is allowed depends on the System.Security.Permissions.SecurityAction that is used.

The security information declared by a security attribute is stored in the metadata of the attribute target and is accessed by the system at run time. Security attributes are used only for declarative security. For imperative security, use the corresponding permission class.

When you use the System.Security.Permissions.SecurityPermissionAttribute class, follow the security action with the permission(s) that are being requested. Each security permission that can be requested, as defined in the System.Security.Permissions.SecurityPermissionFlag enumeration, has a corresponding property in the System.Security.Permissions.SecurityPermissionAttribute class. For example, to demand the ability to access unmanaged code, follow the demand statement with the property setting that is being requested, as follows: SecurityPermissionAttribute(SecurityAction.Demand, UnmanagedCode=true).


An exception to the equivalence between the System.Security.Permissions.SecurityPermissionFlag enumeration and the System.Security.Permissions.SecurityPermissionAttribute properties is that the SecurityPermissionFlag.AllFlags enumeration value is represented by the SecurityAttribute.Unrestricted property (inherited from the System.Security.Permissions.SecurityAttribute class). To demand all security permissions, specify Unrestricted=true.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.


In the following example, the attribute target is an assembly. The attribute declares that the ability to assert permissions on behalf of callers is the minimum permission required for the assembly to execute.

[assembly:SecurityPermissionAttribute(SecurityAction.RequestMinimum, Assertion=true)]


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