CodeAccessSecurityAttribute Třída

Definice

Upozornění

Code Access Security is not supported or honored by the runtime.

Upozornění

CAS support is not available with Silverlight applications.

Určuje třídu základního atributu pro zabezpečení přístupu kódu.

public ref class CodeAccessSecurityAttribute abstract : System::Security::Permissions::SecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public abstract class CodeAccessSecurityAttribute : System.Security.Permissions.SecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
public abstract class CodeAccessSecurityAttribute : System.Security.Permissions.SecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
[System.Serializable]
public abstract class CodeAccessSecurityAttribute : System.Security.Permissions.SecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class CodeAccessSecurityAttribute : System.Security.Permissions.SecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Obsolete("CAS support is not available with Silverlight applications.")]
public abstract class CodeAccessSecurityAttribute : System.Security.Permissions.SecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
[<System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type CodeAccessSecurityAttribute = class
    inherit SecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
type CodeAccessSecurityAttribute = class
    inherit SecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
[<System.Serializable>]
type CodeAccessSecurityAttribute = class
    inherit SecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type CodeAccessSecurityAttribute = class
    inherit SecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Obsolete("CAS support is not available with Silverlight applications.")>]
type CodeAccessSecurityAttribute = class
    inherit SecurityAttribute
Public MustInherit Class CodeAccessSecurityAttribute
Inherits SecurityAttribute
Dědičnost
CodeAccessSecurityAttribute
Odvozené
Atributy

Příklady

Následující příklad ukazuje atribut oprávnění odvozený z CodeAccessSecurityAttribute třídy .

using namespace System;
using namespace System::IO;
using namespace System::Runtime::Remoting;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Reflection;
using namespace MyPermission;

// Use the command line option '/keyfile' or appropriate project settings to sign this assembly.
[assembly:System::Security::AllowPartiallyTrustedCallersAttribute];
[AttributeUsage(AttributeTargets::Method|AttributeTargets::Constructor|AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Assembly,AllowMultiple=true,Inherited=false)]
[Serializable]
public ref class NameIdPermissionAttribute: public CodeAccessSecurityAttribute
{
private:
   String^ m_Name;
   bool m_unrestricted;

public:
   NameIdPermissionAttribute( SecurityAction action )
      : CodeAccessSecurityAttribute( action )
   {
      m_Name = nullptr;
      m_unrestricted = false;
   }


   property String^ Name
   {
      String^ get()
      {
         return m_Name;
      }

      void set( String^ value )
      {
         m_Name = value;
      }

   }
   virtual IPermission^ CreatePermission() override
   {
      if ( m_unrestricted )
      {
         throw gcnew ArgumentException( "Unrestricted permissions not allowed in identity permissions." );
      }
      else
      {
         if ( m_Name == nullptr )
                  return gcnew NameIdPermission( PermissionState::None );
         return gcnew NameIdPermission( m_Name );
      }
   }

};
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);
            }
        }
    }
}
Imports System.IO
Imports System.Runtime.Remoting
Imports System.Security
Imports System.Security.Permissions
Imports System.Reflection
Imports MyPermission

' 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


        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
End Namespace

Poznámky

Upozornění

Zabezpečení přístupu kódu (CAS) bylo ve všech verzích rozhraní .NET Framework a .NET zastaralé. Nedávné verze rozhraní .NET nedodržují poznámky CAS a při použití rozhraní API souvisejících s cas generují chyby. Vývojáři by měli hledat alternativní způsoby provádění úloh zabezpečení.

Tato třída atributu přidruží SecurityAction, například , Demandk vlastnímu atributu zabezpečení.

Typy odvozené z CodeAccessSecurityAttribute se používají k omezení přístupu k prostředkům nebo zabezpečitelným operacím.

Informace o zabezpečení deklarované atributem zabezpečení jsou uloženy v metadatech cíle atributu a systém k němu přistupuje za běhu. Atributy zabezpečení se používají pouze pro deklarativní zabezpečení. Pro imperativní zabezpečení použijte odpovídající třídu oprávnění odvozenou z CodeAccessPermission .

Poznámky pro implementátory

Všechny atributy oprávnění odvozené z této třídy musí mít pouze jeden konstruktor, který přijímá SecurityAction jako jediný parametr.

Konstruktory

CodeAccessSecurityAttribute(SecurityAction)
Zastaralé.
Zastaralé.

Inicializuje novou instanci objektu CodeAccessSecurityAttribute se zadaným SecurityActionparametrem .

Vlastnosti

Action
Zastaralé.
Zastaralé.

Získá nebo nastaví akci zabezpečení.

(Zděděno od SecurityAttribute)
TypeId
Zastaralé.
Zastaralé.

Při implementaci v odvozené třídě získá jedinečný identifikátor pro tuto Attributetřídu .

(Zděděno od Attribute)
Unrestricted
Zastaralé.
Zastaralé.

Získá nebo nastaví hodnotu označující, zda je deklarováno úplné (neomezené) oprávnění k prostředku chráněnému atributem.

(Zděděno od SecurityAttribute)

Metody

CreatePermission()
Zastaralé.
Zastaralé.

Při přepsání v odvozené třídě vytvoří objekt oprávnění, který lze následně serializovat do binární podoby a trvale uložit spolu s SecurityAction v metadatech sestavení.

(Zděděno od SecurityAttribute)
Equals(Object)
Zastaralé.
Zastaralé.

Vrací hodnotu, která určuje, zda je tato instance rovna zadanému objektu.

(Zděděno od Attribute)
GetHashCode()
Zastaralé.
Zastaralé.

Vrátí hodnotu hash pro tuto instanci.

(Zděděno od Attribute)
GetType()
Zastaralé.
Zastaralé.

Type Získá z aktuální instance.

(Zděděno od Object)
IsDefaultAttribute()
Zastaralé.
Zastaralé.

Při přepsání v odvozené třídě označuje, zda je hodnota této instance výchozí hodnotou pro odvozenou třídu.

(Zděděno od Attribute)
Match(Object)
Zastaralé.
Zastaralé.

Při přepsání v odvozené třídě vrátí hodnotu, která označuje, zda se tato instance rovná zadanému objektu.

(Zděděno od Attribute)
MemberwiseClone()
Zastaralé.
Zastaralé.

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ToString()
Zastaralé.
Zastaralé.

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Explicitní implementace rozhraní

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)
Zastaralé.
Zastaralé.

Mapuje sadu názvů na odpovídající sadu identifikátorů pro rozesílání.

(Zděděno od Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)
Zastaralé.
Zastaralé.

Načte informace o typu objektu, které lze použít k získání informací o typu pro rozhraní.

(Zděděno od Attribute)
_Attribute.GetTypeInfoCount(UInt32)
Zastaralé.
Zastaralé.

Získá počet rozhraní typu informací, které objekt poskytuje (0 nebo 1).

(Zděděno od Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)
Zastaralé.
Zastaralé.

Poskytuje přístup k vlastnostem a metodám vystaveným objektem.

(Zděděno od Attribute)

Platí pro

Viz také