GacIdentityPermissionAttribute Classe

Définition

Attention

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

Permet d’appliquer les actions de sécurité de GacIdentityPermission au code à l’aide de la sécurité déclarative. Cette classe ne peut pas être héritée.

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
Héritage
Attributs

Exemples

L'exemple suivant montre l'utilisation de 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

Remarques

Important

Le code partiellement approuvé n’est plus pris en charge. Cet attribut n’a aucun effet dans .NET Core.

Cette classe est utilisée pour s’assurer que les appelants sont inscrits dans le Global Assembly Cache (GAC).

L’étendue de la déclaration autorisée dépend de la SecurityAction valeur utilisée.

Les informations de sécurité déclarées par un attribut de sécurité sont stockées dans les métadonnées de la cible d’attribut et sont accessibles par le système au moment de l’exécution. Les attributs de sécurité sont utilisés uniquement pour la sécurité déclarative. Pour une sécurité impérative, utilisez la classe d’autorisation correspondante. GacIdentityPermission

Important

À compter du .NET Framework 4, les autorisations d’identité ne sont pas utilisées.

Dans les .NET Framework versions 1.0 et 1.1, les demandes sur les autorisations d’identité sont effectives même lorsque l’assembly appelant est entièrement approuvé. Autrement dit, bien que l’assembly appelant ait une confiance totale, une demande d’autorisation d’identité échoue si l’assembly ne répond pas aux critères demandés. Dans la .NET Framework version 2.0, les demandes d’autorisations d’identité sont inefficaces si l’assembly appelant a une confiance totale. Cela garantit la cohérence de toutes les autorisations, éliminant ainsi le traitement des autorisations d’identité comme cas particulier.

Pour plus d’informations sur l’utilisation d’attributs, consultez Attributs.

Constructeurs

GacIdentityPermissionAttribute(SecurityAction)

Initialise une nouvelle instance de la classe GacIdentityPermissionAttribute avec la valeur SecurityAction spécifiée.

Propriétés

Action

Obtient ou définit une action de sécurité.

(Hérité de SecurityAttribute)
TypeId

Lors de l'implémentation dans une classe dérivée, obtient un identificateur unique pour l'objet Attribute.

(Hérité de Attribute)
Unrestricted

Obtient ou définit une valeur indiquant si l'autorisation complète (sans restriction) d'accès à la ressource protégée par l'attribut est déclarée.

(Hérité de SecurityAttribute)

Méthodes

CreatePermission()

Crée un objet GacIdentityPermission.

Equals(Object)

Retourne une valeur qui indique si cette instance est égale à un objet spécifié.

(Hérité de Attribute)
GetHashCode()

Retourne le code de hachage de cette instance.

(Hérité de Attribute)
GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
IsDefaultAttribute()

En cas de substitution dans une classe dérivée, indique si la valeur de cette instance est la valeur par défaut pour la classe dérivée.

(Hérité de Attribute)
Match(Object)

En cas de substitution dans une classe dérivée, retourne une valeur indiquant si cette instance équivaut à un objet spécifié.

(Hérité de Attribute)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l'objet actuel.

(Hérité de Object)

Implémentations d’interfaces explicites

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

Mappe un jeu de noms avec un jeu correspondant d'identificateurs de dispatch.

(Hérité de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Récupère les informations de type pour un objet, qui peuvent être utilisées pour obtenir les informations de type d'une interface.

(Hérité de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Récupère le nombre d'interfaces d'informations de type fourni par un objet (0 ou 1).

(Hérité de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fournit l'accès aux propriétés et aux méthodes exposées par un objet.

(Hérité de Attribute)

S’applique à