다음을 통해 공유


SecurityPermissionFlag 열거형

정의

주의

Code Access Security is not supported or honored by the runtime.

주의

CAS support is not available with Silverlight applications.

보안 권한 개체에 대한 액세스 플래그를 지정합니다.

이 열거형은 멤버 값의 비트 조합을 지원합니다.

public enum class SecurityPermissionFlag
[System.Flags]
[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public enum SecurityPermissionFlag
[System.Flags]
public enum SecurityPermissionFlag
[System.Flags]
[System.Serializable]
public enum SecurityPermissionFlag
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum SecurityPermissionFlag
[System.Flags]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Obsolete("CAS support is not available with Silverlight applications.")]
public enum SecurityPermissionFlag
[<System.Flags>]
[<System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type SecurityPermissionFlag = 
[<System.Flags>]
type SecurityPermissionFlag = 
[<System.Flags>]
[<System.Serializable>]
type SecurityPermissionFlag = 
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type SecurityPermissionFlag = 
[<System.Flags>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Obsolete("CAS support is not available with Silverlight applications.")>]
type SecurityPermissionFlag = 
Public Enum SecurityPermissionFlag
상속
SecurityPermissionFlag
특성

필드

AllFlags 16383

무제한 사용 권한 상태입니다.

Assertion 1

이 코드의 모든 호출자에게 작업에 대한 필수 권한이 있다고 어설션하는 기능입니다.

BindingRedirects 8192

애플리케이션 구성 파일에서 명시적인 바인딩 리디렉션을 수행할 수 있는 권한입니다. 여기에는 통합된 .NET 어셈블리와 .NET 외부에 있는 다른 어셈블리의 리디렉션이 포함됩니다.

ControlAppDomain 1024

AppDomain을 만들고 조작하는 기능입니다.

ControlDomainPolicy 256

도메인 정책을 지정하는 기능입니다.

ControlEvidence 32

공용 언어 런타임에서 제공한 증명 정보를 변경하는 기능을 포함하여 증명 정보를 제공하는 기능입니다.

이것은 완전히 신뢰할 수 있는 코드에만 부여해야 하는 강력한 권한입니다.

ControlPolicy 64

정책을 확인 및 수정하는 기능입니다.

이것은 완전히 신뢰할 수 있는 코드에만 부여해야 하는 강력한 권한입니다.

ControlPrincipal 512

보안 주체 개체를 조작하는 기능입니다.

ControlThread 16

스레드에 특정 고급 작업을 사용하는 기능입니다.

Execution 8

코드를 실행하는 권한입니다. 이 권한이 없으면 관리 코드를 실행할 수 없습니다.

이 플래그는 Deny(), Assert(), PermitOnly()와 같은 스택 한정자와 함께 동적으로 사용하는 경우 아무런 효과가 없습니다.

Infrastructure 4096

원격 컨텍스트 싱크, 엔보이 싱크 및 동적 싱크를 추가하는 등공용 언어 런타임 인프라에 코드를 연결하기 위한 사용 권한입니다.

NoFlags 0

보안 액세스 권한이 없습니다.

RemotingConfiguration 2048

원격 형식 및 채널을 구성하기 위한 사용 권한입니다.

SerializationFormatter 128

serialization 서비스를 제공하는 기능입니다. serialization 포맷터에서 사용합니다.

SkipVerification 4

이 어셈블리에서 코드 확인을 건너뛰는 기능입니다. 이 권한이 부여되면 비안정형 코드를 실행할 수 있습니다.

이것이 완전히 신뢰할 수 있는 코드에만 부여해야 하는 강력한 사용 권한입니다.

이 플래그는 Deny(), Assert(), PermitOnly()와 같은 스택 한정자와 함께 동적으로 사용하는 경우 아무런 효과가 없습니다.

UnmanagedCode 2

비관리 코드를 호출하는 기능입니다.

비관리 코드는 다른 권한을 무시할 수 있으므로 완전히 신뢰할 수 있는 코드에만 부여해야 하는 위험 부담이 있는 권한입니다. PInvoke를 사용 하 여 또는 COM interop를 사용 하 여 호출 네이티브 코드로 이러한 애플리케이션에 사용 됩니다.

예제

다음 예제에서는 열거형을 SecurityPermissionFlag 사용하여 보안 권한을 거부하고 요구하는 방법을 보여 줍니다.

// This sample demonstrates the use of the SecurityPermissionAttribute.
using namespace System;
using namespace System::Security::Permissions;
using namespace System::Security;
class MyClass
{
public:
   static void PermissionDemo()
   {
      try
      {
         DenySecurityPermissions();
         DenyAllSecurityPermissions();
         DoNotDenySecurityPermissions();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( e->Message );
      }

   }


   // This method demonstrates the use of the SecurityPermissionAttribute to deny individual security permissions.
   // Set the Assertion property.
   [SecurityPermissionAttribute(SecurityAction::Deny,Assertion=true)]
   // Set the ControlAppDomain property.
   [SecurityPermissionAttribute(SecurityAction::Deny,ControlAppDomain=true)]
   // Set the ControlDomainPolicy property.
   [SecurityPermissionAttribute(SecurityAction::Deny,ControlDomainPolicy=true)]
   [SecurityPermissionAttribute(SecurityAction::Deny,ControlEvidence=true)]
   // Set the ControlEvidence property.
   [SecurityPermissionAttribute(SecurityAction::Deny,ControlPolicy=true)]
   // Set the ControlPolicy property.
   [SecurityPermissionAttribute(SecurityAction::Deny,ControlPrincipal=true)]
   // Set the ControlPrincipal property.
   // Set the ControlThread property.
   [SecurityPermissionAttribute(SecurityAction::Deny,ControlThread=true)]
   // Set the Execution property.
   [SecurityPermissionAttribute(SecurityAction::Deny,Execution=true)]
   // Set the Flags property.
   [SecurityPermissionAttribute(SecurityAction::Deny,Flags=SecurityPermissionFlag::NoFlags)]
   // Set the Infrastructure property.
   [SecurityPermissionAttribute(SecurityAction::Deny,Infrastructure=true)]
   // Set the RemotingConfiguration property.
   [SecurityPermissionAttribute(SecurityAction::Deny,RemotingConfiguration=true)]
   // Set the SerializationFormatter property.
   [SecurityPermissionAttribute(SecurityAction::Deny,SerializationFormatter=true)]
   // Set the SkipVerification property.
   [SecurityPermissionAttribute(SecurityAction::Deny,SkipVerification=true)]
   // Set the UnmanagedCode property.
   [SecurityPermissionAttribute(SecurityAction::Deny,UnmanagedCode=true)]

   static void DenySecurityPermissions()
   {
      Console::WriteLine( "Executing DenySecurityPermissions." );
      Console::WriteLine( "Denied all permissions individually." );
      TestSecurityPermissions();
   }


   // This method demonstrates the use of SecurityPermissionFlag::AllFlags to deny all security permissions.

   [SecurityPermissionAttribute(SecurityAction::Deny,Flags=SecurityPermissionFlag::AllFlags)]
   static void DenyAllSecurityPermissions()
   {
      Console::WriteLine( "\nExecuting DenyAllSecurityPermissions." );
      Console::WriteLine( "Denied all permissions using SecurityPermissionFlag::AllFlags." );
      TestSecurityPermissions();
   }


   // This method demonstrates the effect of not denying security permissions.
   static void DoNotDenySecurityPermissions()
   {
      Console::WriteLine( "\nExecuting DoNotDenySecurityPermissions." );
      Console::WriteLine( "No permissions have been denied." );
      DemandSecurityPermissions();
   }

   static void TestSecurityPermissions()
   {
      Console::WriteLine( "\nExecuting TestSecurityPermissions.\n" );
      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::Assertion );
         Console::WriteLine( "Demanding SecurityPermissionFlag::Assertion" );
         
         // This demand should cause an exception.
         sp->Demand();
         
         // The TestFailed method is called if an exception is not thrown.
         TestFailed();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::Assertion failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::ControlAppDomain );
         Console::WriteLine( "Demanding SecurityPermissionFlag::ControlAppDomain" );
         sp->Demand();
         TestFailed();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlAppDomain failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::ControlDomainPolicy );
         Console::WriteLine( "Demanding SecurityPermissionFlag::ControlDomainPolicy" );
         sp->Demand();
         TestFailed();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlDomainPolicy failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::ControlEvidence );
         Console::WriteLine( "Demanding SecurityPermissionFlag::ControlEvidence" );
         sp->Demand();
         TestFailed();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlEvidence failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::ControlPolicy );
         Console::WriteLine( "Demanding SecurityPermissionFlag::ControlPolicy" );
         sp->Demand();
         TestFailed();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlPolicy failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::ControlPrincipal );
         Console::WriteLine( "Demanding SecurityPermissionFlag::ControlPrincipal" );
         sp->Demand();
         TestFailed();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlPrincipal failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::ControlThread );
         Console::WriteLine( "Demanding SecurityPermissionFlag::ControlThread" );
         sp->Demand();
         TestFailed();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlThread failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::Execution );
         Console::WriteLine( "Demanding SecurityPermissionFlag::Execution" );
         sp->Demand();
         TestFailed();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::Execution failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::Infrastructure );
         Console::WriteLine( "Demanding SecurityPermissionFlag::Infrastructure" );
         sp->Demand();
         TestFailed();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::Infrastructure failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::RemotingConfiguration );
         Console::WriteLine( "Demanding SecurityPermissionFlag::RemotingConfiguration" );
         sp->Demand();
         TestFailed();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::RemotingConfiguration failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::SerializationFormatter );
         Console::WriteLine( "Demanding SecurityPermissionFlag::SerializationFormatter" );
         sp->Demand();
         TestFailed();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::SerializationFormatter failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::SkipVerification );
         Console::WriteLine( "Demanding SecurityPermissionFlag::SkipVerification" );
         sp->Demand();
         TestFailed();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::SkipVerification failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::UnmanagedCode );
         Console::WriteLine( "Demanding SecurityPermissionFlag::UnmanagedCode" );
         
         // This demand should cause an exception.
         sp->Demand();
         
         // The TestFailed method is called if an exception is not thrown.
         TestFailed();
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::UnmanagedCode failed: {0}", e->Message );
      }

   }

   static void TestFailed()
   {
      Console::WriteLine( "In TestFailed method." );
      Console::WriteLine( "Throwing an exception." );
      throw gcnew Exception;
   }
   
   static void DemandSecurityPermissions()
   {
      Console::WriteLine( "\nExecuting DemandSecurityPermissions.\n" );
      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::Assertion );
         Console::WriteLine( "Demanding SecurityPermissionFlag::Assertion" );
         sp->Demand();
         Console::WriteLine( "Demand for SecurityPermissionFlag::Assertion succeeded." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::Assertion failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::ControlAppDomain );
         Console::WriteLine( "Demanding SecurityPermissionFlag::ControlAppDomain" );
         sp->Demand();
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlAppDomain succeeded." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlAppDomain failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::ControlDomainPolicy );
         Console::WriteLine( "Demanding SecurityPermissionFlag::ControlDomainPolicy" );
         sp->Demand();
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlDomainPolicy succeeded." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlDomainPolicy failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::ControlEvidence );
         Console::WriteLine( "Demanding SecurityPermissionFlag::ControlEvidence" );
         sp->Demand();
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlEvidence succeeded." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlEvidence failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::ControlPolicy );
         Console::WriteLine( "Demanding SecurityPermissionFlag::ControlPolicy" );
         sp->Demand();
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlPolicy succeeded." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlPolicy failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::ControlPrincipal );
         Console::WriteLine( "Demanding SecurityPermissionFlag::ControlPrincipal" );
         sp->Demand();
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlPrincipal succeeded." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlPrincipal failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::ControlThread );
         Console::WriteLine( "Demanding SecurityPermissionFlag::ControlThread" );
         sp->Demand();
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlThread succeeded." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::ControlThread failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::Execution );
         Console::WriteLine( "Demanding SecurityPermissionFlag::Execution" );
         sp->Demand();
         Console::WriteLine( "Demand for SecurityPermissionFlag::Execution succeeded." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::Execution failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::Infrastructure );
         Console::WriteLine( "Demanding SecurityPermissionFlag::Infrastructure" );
         sp->Demand();
         Console::WriteLine( "Demand for SecurityPermissionFlag::Infrastructure succeeded." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::Infrastructure failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::RemotingConfiguration );
         Console::WriteLine( "Demanding SecurityPermissionFlag::RemotingConfiguration" );
         sp->Demand();
         Console::WriteLine( "Demand for SecurityPermissionFlag::RemotingConfiguration succeeded." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::RemotingConfiguration failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::SerializationFormatter );
         Console::WriteLine( "Demanding SecurityPermissionFlag::SerializationFormatter" );
         sp->Demand();
         Console::WriteLine( "Demand for SecurityPermissionFlag::SerializationFormatter succeeded." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::SerializationFormatter failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::SkipVerification );
         Console::WriteLine( "Demanding SecurityPermissionFlag::SkipVerification" );
         sp->Demand();
         Console::WriteLine( "Demand for SecurityPermissionFlag::SkipVerification succeeded." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::SkipVerification failed: {0}", e->Message );
      }

      try
      {
         SecurityPermission^ sp = gcnew SecurityPermission( SecurityPermissionFlag::UnmanagedCode );
         Console::WriteLine( "Demanding SecurityPermissionFlag::UnmanagedCode" );
         sp->Demand();
         Console::WriteLine( "Demand for SecurityPermissionFlag::UnmanagedCode succeeded." );
      }
      catch ( Exception^ e ) 
      {
         Console::WriteLine( "Demand for SecurityPermissionFlag::UnmanagedCode failed: {0}", e->Message );
      }

   }

};

int main()
{
   MyClass::PermissionDemo();
}
// This sample demonstrates the use of the SecurityPermissionAttribute.

using System;
using System.Security.Permissions;
using System.Security;

class MyClass
{
    public static void PermissionDemo()
    {
        try
        {
            DenySecurityPermissions();
            DenyAllSecurityPermissions();
            DoNotDenySecurityPermissions();
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message.ToString());
        }
    }

    // This method demonstrates the use of the SecurityPermissionAttribute to deny individual security permissions.
    // Set the Assertion property.
    [SecurityPermissionAttribute(SecurityAction.Deny, Assertion = true)]
        // Set the ControlAppDomain property.
    [SecurityPermissionAttribute(SecurityAction.Deny, ControlAppDomain = true)]
        // Set the ControlDomainPolicy property.
    [SecurityPermissionAttribute(SecurityAction.Deny, ControlDomainPolicy = true)]
        // Set the ControlEvidence property.
    [SecurityPermissionAttribute(SecurityAction.Deny, ControlEvidence = true)]
        // Set the ControlPolicy property.
    [SecurityPermissionAttribute(SecurityAction.Deny, ControlPolicy = true)]
        // Set the ControlPrincipal property.
    [SecurityPermissionAttribute(SecurityAction.Deny, ControlPrincipal = true)]
        // Set the ControlThread property.
    [SecurityPermissionAttribute(SecurityAction.Deny, ControlThread = true)]
        // Set the Execution property.
    [SecurityPermissionAttribute(SecurityAction.Deny, Execution = true)]
        // Set the Flags property.
    [SecurityPermissionAttribute(SecurityAction.Deny, Flags = SecurityPermissionFlag.NoFlags)]
        // Set the Infrastructure property.
    [SecurityPermissionAttribute(SecurityAction.Deny, Infrastructure = true)]
        // Set the RemotingConfiguration property.
    [SecurityPermissionAttribute(SecurityAction.Deny, RemotingConfiguration = true)]
        // Set the SerializationFormatter property.
    [SecurityPermissionAttribute(SecurityAction.Deny, SerializationFormatter = true)]
        // Set the SkipVerification property.
    [SecurityPermissionAttribute(SecurityAction.Deny, SkipVerification = true)]
        // Set the UnmanagedCode property.
    [SecurityPermissionAttribute(SecurityAction.Deny, UnmanagedCode = true)]

    public static void DenySecurityPermissions()
    {
        Console.WriteLine("Executing DenySecurityPermissions.");
        Console.WriteLine("Denied all permissions individually.");
        TestSecurityPermissions();
    }

    // This method demonstrates the use of SecurityPermissionFlag.AllFlags to deny all security permissions.
    [SecurityPermissionAttribute(SecurityAction.Deny, Flags = SecurityPermissionFlag.AllFlags)]
    public static void DenyAllSecurityPermissions()
    {
        Console.WriteLine("\nExecuting DenyAllSecurityPermissions.");
        Console.WriteLine("Denied all permissions using SecurityPermissionFlag.AllFlags.");
        TestSecurityPermissions();
    }

    // This method demonstrates the effect of not denying security permissions.
    public static void DoNotDenySecurityPermissions()
    {
        Console.WriteLine("\nExecuting DoNotDenySecurityPermissions.");
        Console.WriteLine("No permissions have been denied.");
        DemandSecurityPermissions();
    }

    public static void TestSecurityPermissions()
    {
        Console.WriteLine("\nExecuting TestSecurityPermissions.\n");
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.Assertion);
            Console.WriteLine("Demanding SecurityPermissionFlag.Assertion");
            // This demand should cause an exception.
            sp.Demand();
            // The TestFailed method is called if an exception is not thrown.
            TestFailed();
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.Assertion failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.ControlAppDomain);
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlAppDomain");
            sp.Demand();
            TestFailed();
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlAppDomain failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.ControlDomainPolicy);
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlDomainPolicy");
            sp.Demand();
            TestFailed();
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlDomainPolicy failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.ControlEvidence);
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlEvidence");
            sp.Demand();
            TestFailed();
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlEvidence failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.ControlPolicy);
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlPolicy");
            sp.Demand();
            TestFailed();
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlPolicy failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.ControlPrincipal);
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlPrincipal");
            sp.Demand();
            TestFailed();
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlPrincipal failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.ControlThread);
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlThread");
            sp.Demand();
            TestFailed();
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlThread failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.Execution);
            Console.WriteLine("Demanding SecurityPermissionFlag.Execution");
            sp.Demand();
            TestFailed();
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.Execution failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.Infrastructure);
            Console.WriteLine("Demanding SecurityPermissionFlag.Infrastructure");
            sp.Demand();
            TestFailed();
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.Infrastructure failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.RemotingConfiguration);
            Console.WriteLine("Demanding SecurityPermissionFlag.RemotingConfiguration");
            sp.Demand();
            TestFailed();
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.RemotingConfiguration failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.SerializationFormatter);
            Console.WriteLine("Demanding SecurityPermissionFlag.SerializationFormatter");
            sp.Demand();
            TestFailed();
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.SerializationFormatter failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.SkipVerification);
            Console.WriteLine("Demanding SecurityPermissionFlag.SkipVerification");
            sp.Demand();
            TestFailed();
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.SkipVerification failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
            Console.WriteLine("Demanding SecurityPermissionFlag.UnmanagedCode");
            // This demand should cause an exception.
            sp.Demand();
            // The TestFailed method is called if an exception is not thrown.
            TestFailed();
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.UnmanagedCode failed: " + e.Message);
        }
    }

    public static void TestFailed()
    {
        Console.WriteLine("In TestFailed method.");
        Console.WriteLine("Throwing an exception.");
        throw new Exception();
    }
    
    public static void DemandSecurityPermissions()
    {
        Console.WriteLine("\nExecuting DemandSecurityPermissions.\n");
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.Assertion);
            Console.WriteLine("Demanding SecurityPermissionFlag.Assertion");
            sp.Demand();
            Console.WriteLine("Demand for SecurityPermissionFlag.Assertion succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.Assertion failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.ControlAppDomain);
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlAppDomain");
            sp.Demand();
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlAppDomain succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlAppDomain failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.ControlDomainPolicy);
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlDomainPolicy");
            sp.Demand();
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlDomainPolicy succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlDomainPolicy failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.ControlEvidence);
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlEvidence");
            sp.Demand();
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlEvidence succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlEvidence failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.ControlPolicy);
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlPolicy");
            sp.Demand();
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlPolicy succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlPolicy failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.ControlPrincipal);
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlPrincipal");
            sp.Demand();
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlPrincipal succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlPrincipal failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.ControlThread);
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlThread");
            sp.Demand();
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlThread succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlThread failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.Execution);
            Console.WriteLine("Demanding SecurityPermissionFlag.Execution");
            sp.Demand();
            Console.WriteLine("Demand for SecurityPermissionFlag.Execution succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.Execution failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.Infrastructure);
            Console.WriteLine("Demanding SecurityPermissionFlag.Infrastructure");
            sp.Demand();
            Console.WriteLine("Demand for SecurityPermissionFlag.Infrastructure succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.Infrastructure failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.RemotingConfiguration);
            Console.WriteLine("Demanding SecurityPermissionFlag.RemotingConfiguration");
            sp.Demand();
            Console.WriteLine("Demand for SecurityPermissionFlag.RemotingConfiguration succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.RemotingConfiguration failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.SerializationFormatter);
            Console.WriteLine("Demanding SecurityPermissionFlag.SerializationFormatter");
            sp.Demand();
            Console.WriteLine("Demand for SecurityPermissionFlag.SerializationFormatter succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.SerializationFormatter failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.SkipVerification);
            Console.WriteLine("Demanding SecurityPermissionFlag.SkipVerification");
            sp.Demand();
            Console.WriteLine("Demand for SecurityPermissionFlag.SkipVerification succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.SkipVerification failed: " + e.Message);
        }
        try
        {
            SecurityPermission sp =
                new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
            Console.WriteLine("Demanding SecurityPermissionFlag.UnmanagedCode");
            sp.Demand();
            Console.WriteLine("Demand for SecurityPermissionFlag.UnmanagedCode succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine("Demand for SecurityPermissionFlag.UnmanagedCode failed: " + e.Message);
        }
    }

    static void Main(string[] args)
    {
        PermissionDemo();
    }
}
' This sample demonstrates the use of the SecurityPermissionAttribute.
Imports System.Security.Permissions
Imports System.Security

Class [MyClass]

    Public Shared Sub PermissionDemo()
        Try
            DenySecurityPermissions()
            DenyAllSecurityPermissions()
            DoNotDenySecurityPermissions()
        Catch e As Exception
            Console.WriteLine(e.Message.ToString())
        End Try
    End Sub




    ' This method demonstrates the use of the SecurityPermissionAttribute to deny individual security permissions.
    ' Set the Assertion,UnmanagedCode, ControlAppDomain, ControlDomainPolicy, ontrolEvidence, 
    ' ControlPolicy, ControlPrincipal, ControlThread, Execution, Flags, Infrastructure, 
    ' RemotingConfiguration, SerializationFormatter, and SkipVerification properties.
    <SecurityPermissionAttribute(SecurityAction.Deny, Assertion:=True), _
    SecurityPermissionAttribute(SecurityAction.Deny, ControlAppDomain:=True), _
    SecurityPermissionAttribute(SecurityAction.Deny, ControlDomainPolicy:=True), _
    SecurityPermissionAttribute(SecurityAction.Deny, ControlEvidence:=True), _
    SecurityPermissionAttribute(SecurityAction.Deny, ControlPolicy:=True), _
    SecurityPermissionAttribute(SecurityAction.Deny, ControlPrincipal:=True), _
    SecurityPermissionAttribute(SecurityAction.Deny, ControlThread:=True), _
    SecurityPermissionAttribute(SecurityAction.Deny, Execution:=True), _
    SecurityPermissionAttribute(SecurityAction.Deny, Flags:=SecurityPermissionFlag.NoFlags), _
    SecurityPermissionAttribute(SecurityAction.Deny, Infrastructure:=True), _
    SecurityPermissionAttribute(SecurityAction.Deny, RemotingConfiguration:=True), _
    SecurityPermissionAttribute(SecurityAction.Deny, SerializationFormatter:=True), _
    SecurityPermissionAttribute(SecurityAction.Deny, SkipVerification:=True), _
    SecurityPermissionAttribute(SecurityAction.Deny, UnmanagedCode:=True)> _
    Public Shared Sub DenySecurityPermissions()
        Console.WriteLine("Executing DenySecurityPermissions.")
        Console.WriteLine("Denied all permissions individually.")
        TestSecurityPermissions()
    End Sub


    ' This method demonstrates the use of SecurityPermissionFlag.AllFlags to deny all security permissions.
    <SecurityPermissionAttribute(SecurityAction.Deny, Flags:=SecurityPermissionFlag.AllFlags)> _
    Public Shared Sub DenyAllSecurityPermissions()
        Console.WriteLine(ControlChars.Lf & "Executing DenyAllSecurityPermissions.")
        Console.WriteLine("Denied all permissions using SecurityPermissionFlag.AllFlags.")
        TestSecurityPermissions()
    End Sub


    ' This method demonstrates the effect of not denying security permissions.
    Public Shared Sub DoNotDenySecurityPermissions()
        Console.WriteLine(ControlChars.Lf & "Executing DoNotDenySecurityPermissions.")
        Console.WriteLine("No permissions have been denied.")
        DemandSecurityPermissions()
    End Sub


    Public Shared Sub TestSecurityPermissions()
        Console.WriteLine(ControlChars.Lf & "Executing TestSecurityPermissions." & ControlChars.Lf)
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.Assertion)
            Console.WriteLine("Demanding SecurityPermissionFlag.Assertion")
            ' This demand should cause an exception.
            sp.Demand()
            ' The TestFailed method is called if an exception is not thrown.
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.Assertion failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.ControlAppDomain)
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlAppDomain")
            sp.Demand()
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.ControlAppDomain failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.ControlDomainPolicy)
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlDomainPolicy")
            sp.Demand()
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.ControlDomainPolicy failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.ControlEvidence)
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlEvidence")
            sp.Demand()
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.ControlEvidence failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.ControlPolicy)
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlPolicy")
            sp.Demand()
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.ControlPolicy failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.ControlPrincipal)
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlPrincipal")
            sp.Demand()
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.ControlPrincipal failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.ControlThread)
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlThread")
            sp.Demand()
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.ControlThread failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.Execution)
            Console.WriteLine("Demanding SecurityPermissionFlag.Execution")
            sp.Demand()
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.Execution failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.Infrastructure)
            Console.WriteLine("Demanding SecurityPermissionFlag.Infrastructure")
            sp.Demand()
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.Infrastructure failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.RemotingConfiguration)
            Console.WriteLine("Demanding SecurityPermissionFlag.RemotingConfiguration")
            sp.Demand()
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.RemotingConfiguration failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.SerializationFormatter)
            Console.WriteLine("Demanding SecurityPermissionFlag.SerializationFormatter")
            sp.Demand()
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.SerializationFormatter failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.SkipVerification)
            Console.WriteLine("Demanding SecurityPermissionFlag.SkipVerification")
            sp.Demand()
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.SkipVerification failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.UnmanagedCode)
            Console.WriteLine("Demanding SecurityPermissionFlag.UnmanagedCode")
            ' This demand should cause an exception.
            sp.Demand()
            ' The TestFailed method is called if an exception is not thrown.
            TestFailed()
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.UnmanagedCode failed: " & e.Message))
        End Try
    End Sub


    Public Shared Sub TestFailed()
        Console.WriteLine("In TestFailed method.")
        Console.WriteLine("Throwing an exception.")
        Throw New Exception()
    End Sub

    Public Shared Sub DemandSecurityPermissions()
        Console.WriteLine(ControlChars.Lf & "Executing DemandSecurityPermissions." & ControlChars.Lf)
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.Assertion)
            Console.WriteLine("Demanding SecurityPermissionFlag.Assertion")
            sp.Demand()
            Console.WriteLine("Demand for SecurityPermissionFlag.Assertion succeeded.")
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.Assertion failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.ControlAppDomain)
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlAppDomain")
            sp.Demand()
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlAppDomain succeeded.")
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.ControlAppDomain failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.ControlDomainPolicy)
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlDomainPolicy")
            sp.Demand()
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlDomainPolicy succeeded.")
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.ControlDomainPolicy failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.ControlEvidence)
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlEvidence")
            sp.Demand()
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlEvidence succeeded.")
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.ControlEvidence failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.ControlPolicy)
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlPolicy")
            sp.Demand()
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlPolicy succeeded.")
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.ControlPolicy failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.ControlPrincipal)
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlPrincipal")
            sp.Demand()
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlPrincipal succeeded.")
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.ControlPrincipal failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.ControlThread)
            Console.WriteLine("Demanding SecurityPermissionFlag.ControlThread")
            sp.Demand()
            Console.WriteLine("Demand for SecurityPermissionFlag.ControlThread succeeded.")
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.ControlThread failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.Execution)
            Console.WriteLine("Demanding SecurityPermissionFlag.Execution")
            sp.Demand()
            Console.WriteLine("Demand for SecurityPermissionFlag.Execution succeeded.")
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.Execution failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.Infrastructure)
            Console.WriteLine("Demanding SecurityPermissionFlag.Infrastructure")
            sp.Demand()
            Console.WriteLine("Demand for SecurityPermissionFlag.Infrastructure succeeded.")
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.Infrastructure failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.RemotingConfiguration)
            Console.WriteLine("Demanding SecurityPermissionFlag.RemotingConfiguration")
            sp.Demand()
            Console.WriteLine("Demand for SecurityPermissionFlag.RemotingConfiguration succeeded.")
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.RemotingConfiguration failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.SerializationFormatter)
            Console.WriteLine("Demanding SecurityPermissionFlag.SerializationFormatter")
            sp.Demand()
            Console.WriteLine("Demand for SecurityPermissionFlag.SerializationFormatter succeeded.")
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.SerializationFormatter failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.SkipVerification)
            Console.WriteLine("Demanding SecurityPermissionFlag.SkipVerification")
            sp.Demand()
            Console.WriteLine("Demand for SecurityPermissionFlag.SkipVerification succeeded.")
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.SkipVerification failed: " & e.Message))
        End Try
        Try
            Dim sp As New SecurityPermission(SecurityPermissionFlag.UnmanagedCode)
            Console.WriteLine("Demanding SecurityPermissionFlag.UnmanagedCode")
            sp.Demand()
            Console.WriteLine("Demand for SecurityPermissionFlag.UnmanagedCode succeeded.")
        Catch e As Exception
            Console.WriteLine(("Demand for SecurityPermissionFlag.UnmanagedCode failed: " & e.Message))
        End Try
    End Sub

    Overloads Shared Sub Main(ByVal args() As String)
        PermissionDemo()
    End Sub
End Class

설명

주의

CAS(코드 액세스 보안)는 모든 버전의 .NET Framework 및 .NET에서 더 이상 사용되지 않습니다. 최신 버전의 .NET은 CAS 주석을 적용하지 않으며 CAS 관련 API를 사용하는 경우 오류를 생성합니다. 개발자는 보안 작업을 수행하는 대체 방법을 찾아야 합니다.

이 열거형을 사용 하 여 SecurityPermission입니다.

주의

이러한 플래그의 대부분은 강력하며 신뢰할 수 있는 코드에만 부여되어야 합니다.

적용 대상

추가 정보