CodeAccessSecurityAttribute 클래스
코드 액세스 보안을 위한 기본 특성 클래스를 지정합니다.
네임스페이스: System.Security.Permissions
어셈블리: mscorlib(mscorlib.dll)
구문
‘선언
<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
‘사용 방법
Dim instance As CodeAccessSecurityAttribute
[SerializableAttribute]
[ComVisibleAttribute(true)]
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
public abstract class CodeAccessSecurityAttribute : SecurityAttribute
[SerializableAttribute]
[ComVisibleAttribute(true)]
[AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Constructor|AttributeTargets::Method, AllowMultiple=true, Inherited=false)]
public ref class CodeAccessSecurityAttribute abstract : public 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
설명
이 특성 클래스는 Demand와 같은 SecurityAction을 사용자 지정 보안 특성과 연결합니다.
CodeAccessSecurityAttribute에서 파생되는 형식은 리소스나 보안 가능한 작업에 대한 액세스를 제한하는 데 사용됩니다.
보안 특성에 의해 선언된 보안 정보는 특성 대상의 메타데이터에 저장되며, 런타임에 시스템에서 액세스할 수 있습니다. 보안 특성은 선언적 보안에만 사용됩니다. 명령적 보안에 대해서는 CodeAccessPermission에서 파생된 해당 사용 권한 클래스를 사용합니다.
상속자 참고 사항 이 클래스에서 파생되는 모든 권한 특성은 매개 변수로 SecurityAction만 사용하는 단 하나의 생성자만을 포함해야 합니다.
예제
다음 예제에서는 CodeAccessSecurityAttribute 클래스에서 파생된 권한 특성을 보여 줍니다.
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
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.Object
System.Attribute
System.Security.Permissions.SecurityAttribute
System.Security.Permissions.CodeAccessSecurityAttribute
파생 클래스
스레드로부터의 안전성
이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.
플랫폼
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
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
참고 항목
참조
CodeAccessSecurityAttribute 멤버
System.Security.Permissions 네임스페이스
CodeAccessPermission 클래스