다음을 통해 공유


DnsPermissionAttribute(SecurityAction) 생성자

정의

지정된 DnsPermissionAttribute 값을 사용하여 SecurityAction 클래스의 새 인스턴스를 초기화합니다.

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)

매개 변수

action
SecurityAction

SecurityAction 값 중 하나입니다.

예외

action 매개 변수가 유효한 SecurityAction이 아닌 경우

예제

다음 예제에서는 를 사용하여 DnsPermissionAttribute 사용자 지정 클래스에 선언적 보안을 적용합니다.

//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

설명

이 생성자에 전달되는 값은 SecurityAction 허용 가능한 DnsPermissionAttribute 대상을 지정합니다.

적용 대상

추가 정보