CodeAccessSecurityAttribute Class
Assembly: mscorlib (in mscorlib.dll)
[SerializableAttribute] [ComVisibleAttribute(true)] [AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method, AllowMultiple=true, Inherited=false)] public abstract class CodeAccessSecurityAttribute : SecurityAttribute
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ /** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method, AllowMultiple=true, Inherited=false) */ public abstract class CodeAccessSecurityAttribute extends SecurityAttribute
SerializableAttribute ComVisibleAttribute(true) AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method, AllowMultiple=true, Inherited=false) public abstract class CodeAccessSecurityAttribute extends SecurityAttribute
This attribute class associates a SecurityAction, for example, Demand, with a custom security attribute.
The types that derive from CodeAccessSecurityAttribute are used to help restrict access to resources or securable operations.
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. Use the corresponding permission class derived from CodeAccessPermission for imperative security.
Notes to Inheritors All permission attributes derived from this class must have only a single constructor that takes a SecurityAction as its only parameter.The following example shows a permission attribute derived from the CodeAccessSecurityAttribute class.
using System; using System.IO; using System.Runtime.Remoting; using System.Security; using System.Security.Permissions; using System.Reflection; using MyPermission; // Use the command line option '/keyfile' or appropriate project settings to sign this assembly. [assembly: System.Security.AllowPartiallyTrustedCallersAttribute ()] namespace MyPermissionAttribute { [AttributeUsage (AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)] [Serializable] sealed public class NameIdPermissionAttribute : CodeAccessSecurityAttribute { private String m_Name = null; private bool m_unrestricted = false; public NameIdPermissionAttribute (SecurityAction action): base( action ) { } public String Name { get { return m_Name; } set { m_Name = value; } } public override IPermission CreatePermission () { if (m_unrestricted) { throw new ArgumentException ("Unrestricted permissions not allowed in identity permissions."); } else { if (m_Name == null) return new NameIdPermission (PermissionState.None); return new NameIdPermission (m_Name); } } } }
System.Attribute
System.Security.Permissions.SecurityAttribute
System.Security.Permissions.CodeAccessSecurityAttribute
Derived Classes
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.