Export (0) Print
Expand All

DnsPermissionAttribute Constructor

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

[Visual Basic]
Public Sub New( _
   ByVal action As SecurityAction _
)
[C#]
public DnsPermissionAttribute(
   SecurityAction action
);
[C++]
public: DnsPermissionAttribute(
   SecurityAction action
);
[JScript]
public function DnsPermissionAttribute(
   action : SecurityAction
);

Parameters

action
One of the SecurityAction values.

Exceptions

Exception Type Condition
ArgumentException The action parameter is not a valid SecurityAction.

Remarks

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

Example

[Visual Basic, C#, C++] The following example uses DnsPermissionAttribute to apply declarative security to a custom class.

[Visual Basic] 
' 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

[C#] 
//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());
}

[C++] 
//Uses the DnsPermissionAttribute to restrict access only to those who have permission.
[DnsPermission(SecurityAction::Demand, Unrestricted = true)]
public __gc class MyClass{
public:
    static IPAddress* GetIPAddress(){
        IPAddress* ipAddress = Dns::Resolve(S"localhost")->AddressList[0];
        return ipAddress;
    }
};

int main(){
    try{
        //Grants Access.
        Console::WriteLine(S" Access granted\n The local host IP Address is :{0}", MyClass::GetIPAddress());
    }
    // Denies Access.
    catch(SecurityException* securityException){
        Console::WriteLine(S"Access denied");    
        Console::WriteLine(securityException->ToString());
    }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

DnsPermissionAttribute Class | DnsPermissionAttribute Members | System.Net Namespace | SecurityAction

Show:
© 2014 Microsoft