CodeAccessSecurityAttribute Class
Assembly: mscorlib (in mscorlib.dll)
'Declaration <SerializableAttribute> _ <ComVisibleAttribute(True)> _ <AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Constructor Or AttributeTargets.Method, AllowMultiple:=True, Inherited:=False)> _ Public MustInherit Class CodeAccessSecurityAttribute Inherits SecurityAttribute 'Usage Dim instance As CodeAccessSecurityAttribute
/** @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.
Imports System Imports System.IO Imports System.Runtime.Remoting Imports System.Security Imports System.Security.Permissions Imports System.Reflection Imports MyPermission Imports Microsoft.VisualBasic ' Use the command line option '/keyfile' or appropriate project settings to sign this assembly. <Assembly: System.Security.AllowPartiallyTrustedCallersAttribute()> Namespace MyPermissionAttribute <AttributeUsage(AttributeTargets.All, AllowMultiple:=True, Inherited:=False)> Public NotInheritable Class NameIdPermissionAttribute Inherits CodeAccessSecurityAttribute Private m_Name As String = Nothing Private m_unrestricted As Boolean = False Public Sub New(ByVal action As SecurityAction) MyBase.New(action) End Sub 'New Public Property Name() As String Get Return m_name End Get Set(ByVal Value As String) m_name = Value End Set End Property Public Overrides Function CreatePermission() As IPermission If m_unrestricted Then Throw New ArgumentException("Unrestricted permissions not allowed in identity permissions.") Else If m_name Is Nothing Then Return New NameIdPermission(PermissionState.None) End If Return New NameIdPermission(m_name) End If End Function 'CreatePermission End Class ' NameIdPermissionAttribute End Namespace
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.