This documentation is archived and is not being maintained.

DnsPermissionAttribute Class

Specifies permission to request information from Domain Name Servers.

For a list of all members of this type, see DnsPermissionAttribute Members.


[Visual Basic]
<AttributeUsage(AttributeTargets.Assembly Or AttributeTargets.Class _
   Or AttributeTargets.Struct Or AttributeTargets.Constructor Or _
NotInheritable Public Class DnsPermissionAttribute
   Inherits CodeAccessSecurityAttribute
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class
   | AttributeTargets.Struct | AttributeTargets.Constructor |
public sealed class DnsPermissionAttribute :
[AttributeUsage(AttributeTargets::Assembly |
   AttributeTargets::Class | AttributeTargets::Struct |
   AttributeTargets::Constructor | AttributeTargets::Method)]
public __gc __sealed class DnsPermissionAttribute : public
   AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class |
   AttributeTargets.Struct | AttributeTargets.Constructor |
class DnsPermissionAttribute extends

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


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. The system then accesses this information at run-time. The SecurityAction passed to the constructor determines the allowable DNS targets.

These security attributes are used only for Declarative Security. For Imperative Security, use the corresponding DnsPermission class.

Security access is either fully restricted, or fully unrestricted. Set the Unrestricted property to true to grant access, or false for no access. Set this property as a named parameter.

For more information about using attributes, see Extending Metadata Using Attributes.


[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()
         ' 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")
      End Try

//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");    

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

int main(){
        //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");    

[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.


Namespace: System.Net

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System (in System.dll)

See Also

DnsPermissionAttribute Members | System.Net Namespace | CodeAccessSecurityAttribute