CodeAccessSecurityAttribute Klasa

Definicja

Przestroga

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

Przestroga

CAS support is not available with Silverlight applications.

Określa klasę atrybutu podstawowego dla zabezpieczeń dostępu kodu.

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
Dziedziczenie
CodeAccessSecurityAttribute
Pochodne
Atrybuty

Przykłady

W poniższym przykładzie pokazano atrybut uprawnień pochodzący z CodeAccessSecurityAttribute klasy .

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

Uwagi

Przestroga

Zabezpieczenia dostępu kodu (CAS) zostały uznane za przestarzałe we wszystkich wersjach .NET Framework i .NET. Najnowsze wersje platformy .NET nie honorują adnotacji CAS i generują błędy, jeśli są używane interfejsy API związane z usługą CAS. Deweloperzy powinni szukać alternatywnych sposobów wykonywania zadań zabezpieczeń.

Ta klasa atrybutu SecurityActionkojarzy , na przykład Demand, z niestandardowym atrybutem zabezpieczeń.

Typy pochodzące z CodeAccessSecurityAttribute programu są używane do ograniczania dostępu do zasobów lub zabezpieczanych operacji.

Informacje o zabezpieczeniach zadeklarowane przez atrybut zabezpieczeń są przechowywane w metadanych obiektu docelowego atrybutu i są dostępne przez system w czasie wykonywania. Atrybuty zabezpieczeń są używane tylko w przypadku zabezpieczeń deklaratywnych. Użyj odpowiedniej klasy uprawnień pochodzącej z CodeAccessPermission programu na potrzeby zabezpieczeń imperatywnych.

Uwagi dotyczące implementowania

Wszystkie atrybuty uprawnień pochodzące z tej klasy muszą mieć tylko jeden konstruktor, który przyjmuje SecurityAction jako jedyny parametr.

Konstruktory

CodeAccessSecurityAttribute(SecurityAction)

Inicjuje nowe wystąpienie klasy CodeAccessSecurityAttribute z określonym SecurityActionelementem .

Właściwości

Action

Pobiera lub ustawia akcję zabezpieczeń.

(Odziedziczone po SecurityAttribute)
TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego Attributeelementu .

(Odziedziczone po Attribute)
Unrestricted

Pobiera lub ustawia wartość wskazującą, czy zadeklarowane jest pełne (nieograniczone) uprawnienie do zasobu chronionego przez atrybut.

(Odziedziczone po SecurityAttribute)

Metody

CreatePermission()

Po przesłonięciu w klasie pochodnej tworzy obiekt uprawnień, który następnie można serializować w postaci binarnej i trwale przechowywany wraz z SecurityAction metadanymi zestawu.

(Odziedziczone po SecurityAttribute)
Equals(Object)

Zwraca wartość wskazującą, czy to wystąpienie jest równe podanemu obiektowi.

(Odziedziczone po Attribute)
GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

(Odziedziczone po Attribute)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
IsDefaultAttribute()

W przypadku zastąpienia w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną klasy pochodnej.

(Odziedziczone po Attribute)
Match(Object)

Po przesłonięciu w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

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

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie dla obiektu, który może służyć do pobierania informacji o typie dla interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy

Zobacz też