DnsPermissionAttribute Constructor
Collapse the table of content
Expand the table of content

DnsPermissionAttribute Constructor (SecurityAction)


Initializes a new instance of the DnsPermissionAttribute class with the specified SecurityAction value.

Namespace:   System.Net
Assembly:  System (in System.dll)

public DnsPermissionAttribute(
	SecurityAction action


Type: System.Security.Permissions.SecurityAction

One of the SecurityAction values.

Exception Condition

The action parameter is not a valid SecurityAction.

The SecurityAction value that is passed to this constructor specifies the allowable DnsPermissionAttribute targets.

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 class MyClass{

public static IPAddress GetIPAddress(){
     IPAddress ipAddress = Dns.Resolve("localhost").AddressList[0];
     return ipAddress;
public static void Main(){
     //Grants Access.
     Console.WriteLine(" Access granted\n The local host IP Address is :" + 
// Denies Access.
catch(SecurityException securityException){
     Console.WriteLine("Access denied");	

.NET Framework
Available since 1.1
Return to top
© 2016 Microsoft