GacIdentityPermissionAttribute Classe

Definizione

Attenzione

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

Consente di applicare azioni di sicurezza per GacIdentityPermission al codice usando la sicurezza dichiarativa. La classe non può essere ereditata.

public ref class GacIdentityPermissionAttribute sealed : System::Security::Permissions::CodeAccessSecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
public sealed class GacIdentityPermissionAttribute : System.Security.Permissions.CodeAccessSecurityAttribute
[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 sealed class GacIdentityPermissionAttribute : System.Security.Permissions.CodeAccessSecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public sealed class GacIdentityPermissionAttribute : System.Security.Permissions.CodeAccessSecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
type GacIdentityPermissionAttribute = class
    inherit CodeAccessSecurityAttribute
[<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 GacIdentityPermissionAttribute = class
    inherit CodeAccessSecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type GacIdentityPermissionAttribute = class
    inherit CodeAccessSecurityAttribute
Public NotInheritable Class GacIdentityPermissionAttribute
Inherits CodeAccessSecurityAttribute
Ereditarietà
Attributi

Esempio

L'esempio seguente illustra l'uso di GacIdentityPermissionAttribute.

// To run this sample you must create a strong-name key named snkey.snk 
// using the Strong Name tool (sn.exe).  Both the library assembly and the 
// application assembly that calls it must be signed with that key.  
// To run successfully, the application assembly must be in the global 
// assembly cache.
// This console application can be created using the following code.

//#using <mscorlib.dll>
//#using <ClassLibrary1.dll>
//using namespace System;
//using namespace System::Security;
//using namespace System::Reflection;
//using namespace ClassLibrary1;
//[assembly: AssemblyVersion(S"1.0.555.0")]
//[assembly: AssemblyKeyFile(S"snKey.snk")];
//int main()
//{ 
//    try
//    {
//        Class1* myLib = new Class1();
//        myLib->DoNothing();
//
//        Console::WriteLine(S"Exiting the sample.");
//    }
//    catch (Exception* e)
//    {
//        Console::WriteLine(e->Message);
//    }
//}
using namespace System;
using namespace System::Security::Permissions;

namespace ClassLibrary1
{
   // Demand that the calling program be in the global assembly cache.
   [GacIdentityPermissionAttribute(SecurityAction::Demand)]
   public ref class Class1
   {
   public:
      void DoNothing()
      {
         Console::WriteLine( "Exiting the library program." );
      }
   };
}
// To run this sample you must create a strong-name key named snkey.snk 
// using the Strong Name tool (sn.exe).  Both the library assembly and the 
// application assembly that calls it must be signed with that key.  
// To run successfully, the application assembly must be in the global 
// assembly cache.
// This console application can be created using the following code.

//using System;
//using System.Security;
//using System.Reflection;
//using ClassLibrary1;
//[assembly: AssemblyVersion("1.0.555.0")]
//[assembly: AssemblyKeyFile("snKey.snk")]
//class MyClass
//{
//    static void Main(string[] args)
//    {
//        try
//        {
//            Class1 myLib = new Class1();
//            myLib.DoNothing();
//
//            Console.WriteLine("Exiting the sample.");
//        }
//        catch (Exception e)
//        {
//        Console.WriteLine(e.Message);
//        }
//    }
//}
using System;
using System.Security.Permissions;

namespace ClassLibrary1
{
    // Demand that the calling program be in the global assembly cache.
    [GacIdentityPermissionAttribute(SecurityAction.Demand)]
    public class Class1
    {
        public void DoNothing()
        {
            Console.WriteLine("Exiting the library program.");
        }
    }
}
' To run this sample you must create a strong-name key named snkey.snk 
' using the Strong Name tool (sn.exe).  Both the library assembly and the 
' application assembly that calls it must be signed with that key.  
' To run successfully, the application assembly must be in the global 
' assembly cache.
' This console application can be created using the following code.

'Imports System.Security
'Imports System.Security.Policy
'Imports System.Security.Principal
'Imports System.Security.Permissions
'Imports ClassLibraryVB

'Class [MyClass]
'
'    Overloads Shared Sub Main(ByVal args() As String)
'        Try
'           Dim myLib As New Class1
'            myLib.DoNothing()
'
'            Console.WriteLine("Exiting the sample.")
'        Catch e As Exception
'            Console.WriteLine(e.Message)
'        End Try
'    End Sub
'End Class
Imports System.Security.Permissions

' Demand that the calling program be in the global assembly cache.
<GacIdentityPermissionAttribute(SecurityAction.Demand)> _
Public Class Class1
    Public Sub DoNothing()
        Console.WriteLine("Exiting the library program.")
    End Sub
End Class

Commenti

Attenzione

La sicurezza di accesso al codice è stata deprecata in tutte le versioni di .NET Framework e .NET. Le versioni recenti di .NET non rispettano le annotazioni CAS e generano errori se vengono usate API correlate a CAS. Gli sviluppatori devono cercare mezzi alternativi per eseguire attività di sicurezza.

Questa classe viene usata per assicurarsi che i chiamanti siano registrati nella global assembly cache (GAC).

L'ambito della dichiarazione consentita dipende dal SecurityAction valore utilizzato.

Le informazioni di sicurezza dichiarate da un attributo di sicurezza vengono archiviate nei metadati della destinazione dell'attributo e accedono al sistema in fase di esecuzione. Gli attributi di sicurezza vengono usati solo per la sicurezza dichiarativa. Per la sicurezza imperativa, usare la classe di autorizzazione corrispondente, GacIdentityPermission.

Importante

A partire da .NET Framework 4, le autorizzazioni di identità non vengono usate.

Nelle versioni di .NET Framework 1.0 e 1.1, le richieste sulle autorizzazioni di identità sono valide anche quando l'assembly chiamante è completamente attendibile. Vale a dire, anche se l'assembly chiamante ha attendibilità completa, una richiesta di autorizzazione identity non riesce se l'assembly non soddisfa i criteri richiesti. Nella versione 2.0 di .NET Framework le richieste di autorizzazioni di identità sono inefficaci se l'assembly chiamante ha attendibilità completa. Ciò garantisce la coerenza per tutte le autorizzazioni, eliminando il trattamento delle autorizzazioni di identità come caso speciale.

Per altre informazioni sull'uso degli attributi, vedere Attributi.

Costruttori

GacIdentityPermissionAttribute(SecurityAction)
Obsoleti.

Inizializza una nuova istanza della classe GacIdentityPermissionAttribute con il valore SecurityAction specificato.

Proprietà

Action
Obsoleti.

Ottiene o imposta un'azione di sicurezza.

(Ereditato da SecurityAttribute)
TypeId
Obsoleti.

Quando è implementata in una classe derivata, ottiene un identificatore univoco della classe Attribute.

(Ereditato da Attribute)
Unrestricted
Obsoleti.

Ottiene o imposta un valore che indica se esiste una dichiarazione di autorizzazione completa, ovvero senza restrizioni, alla risorsa protetta dall’attributo.

(Ereditato da SecurityAttribute)

Metodi

CreatePermission()
Obsoleti.

Crea un nuovo oggetto GacIdentityPermission.

Equals(Object)
Obsoleti.

Restituisce un valore che indica se questa istanza è uguale a un oggetto specificato.

(Ereditato da Attribute)
GetHashCode()
Obsoleti.

Restituisce il codice hash per l'istanza.

(Ereditato da Attribute)
GetType()
Obsoleti.

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
IsDefaultAttribute()
Obsoleti.

In caso di override in una classe derivata, indica se il valore di questa istanza è il valore predefinito per la classe derivata.

(Ereditato da Attribute)
Match(Object)
Obsoleti.

Quando è sottoposto a override in una classe derivata, restituisce un valore che indica se questa istanza equivale a un oggetto specificato.

(Ereditato da Attribute)
MemberwiseClone()
Obsoleti.

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()
Obsoleti.

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Implementazioni dell'interfaccia esplicita

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

Esegue il mapping di un set di nomi a un set corrispondente di ID dispatch.

(Ereditato da Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)
Obsoleti.

Recupera le informazioni sul tipo relative a un oggetto, che possono essere usate per ottenere informazioni sul tipo relative a un'interfaccia.

(Ereditato da Attribute)
_Attribute.GetTypeInfoCount(UInt32)
Obsoleti.

Recupera il numero delle interfacce di informazioni sul tipo fornite da un oggetto (0 o 1).

(Ereditato da Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)
Obsoleti.

Fornisce l'accesso a proprietà e metodi esposti da un oggetto.

(Ereditato da Attribute)

Si applica a