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
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.
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.