GacIdentityPermissionAttribute Classe

Definição

Cuidado

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

Permite que as ações de segurança para GacIdentityPermission sejam aplicadas ao código usando a segurança declarativa. Essa classe não pode ser herdada.

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
Herança
Atributos

Exemplos

O exemplo a seguir demonstra o uso 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

Comentários

Importante

Não há mais suporte para código parcialmente confiável. Esse atributo não tem efeito no .NET Core.

Essa classe é usada para garantir que os chamadores sejam registrados no GAC (cache de assembly global).

O escopo da declaração permitida depende do SecurityAction valor usado.

As informações de segurança declaradas por um atributo de segurança são armazenadas nos metadados do destino do atributo e são acessadas pelo sistema em tempo de execução. Os atributos de segurança são usados apenas para segurança declarativa. Para segurança imperativa, use a classe de permissão correspondente. GacIdentityPermission

Importante

A partir do .NET Framework 4, as permissões de identidade não são usadas.

No .NET Framework versões 1.0 e 1.1, as exigências sobre as permissões de identidade são efetivas mesmo quando o assembly de chamada é totalmente confiável. Ou seja, embora o assembly de chamada tenha total confiança, uma demanda por uma permissão de identidade falhará se o assembly não atender aos critérios exigidos. No .NET Framework versão 2.0, as demandas por permissões de identidade serão ineficazes se o assembly de chamada tiver total confiança. Isso garante a consistência de todas as permissões, eliminando o tratamento de permissões de identidade como um caso especial.

Para obter mais informações sobre como usar atributos, consulte Atributos.

Construtores

GacIdentityPermissionAttribute(SecurityAction)

Inicializa uma nova instância da classe GacIdentityPermissionAttribute com o valor SecurityAction especificado.

Propriedades

Action

Obtém ou define uma ação de segurança.

(Herdado de SecurityAttribute)
TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.

(Herdado de Attribute)
Unrestricted

Obtém ou define um valor que indica se a permissão total (irrestrita) para o recurso protegido pelo atributo é declarada.

(Herdado de SecurityAttribute)

Métodos

CreatePermission()

Cria um novo objeto GacIdentityPermission.

Equals(Object)

Retorna um valor que indica se essa instância é igual a um objeto especificado.

(Herdado de Attribute)
GetHashCode()

Retorna o código hash para a instância.

(Herdado de Attribute)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
IsDefaultAttribute()

Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.

(Herdado de Attribute)
Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Implantações explícitas de interface

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

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.

(Herdado de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).

(Herdado de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornece acesso a propriedades e métodos expostos por um objeto.

(Herdado de Attribute)

Aplica-se a