DnsPermissionAttribute(SecurityAction) Constructeur
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Initialise une nouvelle instance de la classe DnsPermissionAttribute avec la valeur SecurityAction spécifiée.
public:
DnsPermissionAttribute(System::Security::Permissions::SecurityAction action);
public DnsPermissionAttribute (System.Security.Permissions.SecurityAction action);
new System.Net.DnsPermissionAttribute : System.Security.Permissions.SecurityAction -> System.Net.DnsPermissionAttribute
Public Sub New (action As SecurityAction)
Paramètres
- action
- SecurityAction
Une des valeurs de l'objet SecurityAction.
Exceptions
Le paramètre action
n’est pas une valeur SecurityAction valide.
Exemples
L’exemple suivant utilise DnsPermissionAttribute pour appliquer une sécurité déclarative à une classe personnalisée.
//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() );
}
}
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
Remarques
La SecurityAction valeur passée à ce constructeur spécifie les cibles autorisées DnsPermissionAttribute .