DnsPermissionAttribute Classe
Definição
Cuidado
Code Access Security is not supported or honored by the runtime.
Especifica a permissão para solicitar informações de servidores de nome de domínio.Specifies permission to request information from Domain Name Servers.
public ref class DnsPermissionAttribute 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 DnsPermissionAttribute : 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 DnsPermissionAttribute : 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.Serializable]
public sealed class DnsPermissionAttribute : 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 DnsPermissionAttribute = 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 DnsPermissionAttribute = 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.Serializable>]
type DnsPermissionAttribute = class
inherit CodeAccessSecurityAttribute
Public NotInheritable Class DnsPermissionAttribute
Inherits CodeAccessSecurityAttribute
- Herança
- Atributos
Exemplos
O exemplo a seguir usa DnsPermissionAttribute para aplicar a segurança declarativa a uma classe personalizada.The following example uses DnsPermissionAttribute to apply declarative security to a custom class.
//Uses the DnsPermissionAttribute to restrict access only to those who have permission.
[DnsPermission(SecurityAction::Demand,Unrestricted=true)]
public ref class MyClass
{
public:
static IPAddress^ GetIPAddress()
{
IPAddress^ ipAddress = Dns::Resolve( "localhost" )->AddressList[ 0 ];
return ipAddress;
}
};
int main()
{
try
{
//Grants Access.
Console::WriteLine( " Access granted\n The local host IP Address is :{0}", MyClass::GetIPAddress() );
}
// Denies Access.
catch ( SecurityException^ securityException )
{
Console::WriteLine( "Access denied" );
Console::WriteLine( securityException->ToString() );
}
}
//Uses the DnsPermissionAttribute to restrict access only to those who have permission.
[DnsPermission(SecurityAction.Demand, Unrestricted = true)]
public class MyClass
{
public static IPAddress GetIPAddress()
{
IPAddress ipAddress = Dns.Resolve("localhost").AddressList[0];
return ipAddress;
}
public static void Main()
{
try
{
//Grants Access.
Console.WriteLine(" Access granted\n The local host IP Address is :" +
MyClass.GetIPAddress().ToString());
}
// Denies Access.
catch (SecurityException securityException)
{
Console.WriteLine("Access denied");
Console.WriteLine(securityException.ToString());
}
' Uses the DnsPermissionAttribute to restrict access only to those who have permission.
<DnsPermission(SecurityAction.Demand, Unrestricted := true)> _
Public Class MyClass1
Public Shared Function GetIPAddress() As IPAddress
Dim ipAddress As IPAddress = Dns.Resolve("localhost").AddressList(0)
Return ipAddress
End Function 'GetIPAddress
Public Shared Sub Main()
Try
' Grants Access.
Console.WriteLine(("Access granted" + ControlChars.NewLine + " The local host IP Address is :" + MyClass1.GetIPAddress().ToString()))
' Denies Access.
Catch securityException As SecurityException
Console.WriteLine("Access denied")
Console.WriteLine(securityException.ToString())
End Try
End Sub
End Class
Comentários
As informações de segurança declaradas pelo DnsPermissionAttribute são armazenadas nos metadados do destino do atributo, que é a classe à qual o DnsPermissionAttribute é aplicado.The security information declared by DnsPermissionAttribute is stored in the metadata of the attribute target, which is the class to which the DnsPermissionAttribute is applied. O sistema então acessa essas informações em tempo de execução.The system then accesses this information at run time. O SecurityAction que é passado para o Construtor determina os destinos DNS permitidos.The SecurityAction that is passed to the constructor determines the allowable DNS targets.
Esses atributos de segurança são usados apenas para segurança declarativa.These security attributes are used only for Declarative Security. Para segurança imperativa, use a DnsPermission classe correspondente.For Imperative Security, use the corresponding DnsPermission class.
O acesso à segurança é totalmente restrito ou totalmente irrestrito.Security access is either fully restricted or fully unrestricted. Defina a Unrestricted propriedade como true para conceder acesso ou false sem acesso.Set the Unrestricted property to true to grant access, or false for no access. Defina essa propriedade como um parâmetro nomeado.Set this property as a named parameter.
Para obter mais informações sobre como usar atributos, consulte atributos.For more information about using attributes, see Attributes.
Construtores
| DnsPermissionAttribute(SecurityAction) |
Inicializa uma nova instância da classe DnsPermissionAttribute com o valor SecurityAction especificado.Initializes a new instance of the DnsPermissionAttribute class with the specified SecurityAction value. |
Propriedades
| Action |
Obtém ou define uma ação de segurança.Gets or sets a security action. (Herdado de SecurityAttribute) |
| TypeId |
Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.When implemented in a derived class, gets a unique identifier for this 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.Gets or sets a value indicating whether full (unrestricted) permission to the resource protected by the attribute is declared. (Herdado de SecurityAttribute) |
Métodos
| CreatePermission() |
Cria e retorna uma nova instância da classe DnsPermission.Creates and returns a new instance of the DnsPermission class. |
| Equals(Object) |
Retorna um valor que indica se essa instância é igual a um objeto especificado.Returns a value that indicates whether this instance is equal to a specified object. (Herdado de Attribute) |
| GetHashCode() |
Retorna o código hash para a instância.Returns the hash code for this instance. (Herdado de Attribute) |
| GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (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.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (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.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Herdado de Attribute) |
| MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
| ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (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.Maps a set of names to a corresponding set of dispatch identifiers. (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.Retrieves the type information for an object, which can be used to get the type information for an 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).Retrieves the number of type information interfaces that an object provides (either 0 or 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.Provides access to properties and methods exposed by an object. (Herdado de Attribute) |