Description



Description

[Note: The security information declared by a security attribute is stored in the metadata of the attribute target, and is accessed by the system at runtime. Security attributes are used for declarative security only. For imperative security, use the corresponding permission class, DnsPermission. The allowable DnsPermissionAttribute targets are determined by the System.Security.Permissions.SecurityAction passed to the constructor.]

Example

using System;

using System.Net;

using System.Security;

using System.Security.Permissions;





[DnsPermission(SecurityAction.Demand, Unrestricted = true)]

public class DnsTest

{

    public static String GetLocalHostName()

    {

        return Dns.GetHostName();

    }

}



public class DnsPermissionAttributeSample

{

    public static void Main()

    {

        try

        {

            Console.WriteLine("DnsTest.GetLocalHostName returned: '{0}'",

                DnsTest.GetLocalHostName());

        }

        catch (Exception e)

        {

            Console.WriteLine(e.Message);

        }

        Console.WriteLine();

        Console.WriteLine();

        Console.WriteLine("Press Enter to continue");

        Console.ReadLine();

    }

}


The output is


DnsTest.GetLocalHostName returned: 'MachineName'





Press Enter to continue