Compartilhar via


SecurityPermissionFlag Enumeração

Definição

Cuidado

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

Cuidado

CAS support is not available with Silverlight applications.

Especifica sinalizadores de acesso para o objeto de permissão de segurança.

Essa enumeração dá suporte a uma combinação bit a bit dos valores de membro.

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
Herança
SecurityPermissionFlag
Atributos

Campos

AllFlags 16383

O estado irrestrito da permissão.

Assertion 1

Capacidade de declarar que todos os chamadores desse código têm a permissão necessária para a operação.

BindingRedirects 8192

Permissão para executar o redirecionamento de associação explícita no arquivo de configuração de aplicativo. Isso inclui o redirecionamento dos assemblies do .NET que foram unificados, bem como outros assemblies localizados fora do .NET.

ControlAppDomain 1024

Capacidade de criar e manipular um AppDomain.

ControlDomainPolicy 256

Capacidade de especificar a política de domínio.

ControlEvidence 32

Capacidade de fornecer evidências, incluindo a capacidade de alterar a evidência fornecida pelo Common Language Runtime.

Essa é uma permissão avançada que deve ser concedida apenas a código altamente confiável.

ControlPolicy 64

Capacidade de exibir e modificar a política.

Essa é uma permissão avançada que deve ser concedida apenas a código altamente confiável.

ControlPrincipal 512

Capacidade de manipular o objeto de entidade de segurança.

ControlThread 16

Capacidade de usar determinadas operações avançadas em threads.

Execution 8

Permissão que o código seja executado. Sem essa permissão, o código gerenciado não será executado.

Esse sinalizador não tem efeito quando usado de forma dinâmica com modificadores de pilha, como Deny(), Assert() e PermitOnly().

Infrastructure 4096

Permissão para conectar o código à infraestrutura de Common Language Runtime, como a adição de Coletores de contexto de comunicação remota, coletores Envoy e coletores dinâmicos.

NoFlags 0

Sem acesso de segurança.

RemotingConfiguration 2048

Permissão para configurar canais e tipos de comunicação remota.

SerializationFormatter 128

Capacidade de fornecer serviços de serialização. Usado por formatadores de serialização.

SkipVerification 4

Capacidade de ignorar a verificação de código neste assembly. O código não verificável poderá ser executado se esta permissão for concedida.

Essa é uma permissão avançada que deve ser concedida apenas a código altamente confiável.

Esse sinalizador não tem efeito quando usado de forma dinâmica com modificadores de pilha, como Deny(), Assert() e PermitOnly().

UnmanagedCode 2

Capacidade de chamar código não gerenciado.

Uma vez que o código não gerenciado potencialmente permite que outras permissões sejam ignoradas, essa é uma permissão perigosa que deve ser concedida apenas a código altamente confiável. Ela é usada para aplicativos como o código nativo de chamada usando invocação de plataforma ou interoperabilidade COM.

Exemplos

O exemplo a seguir mostra o uso da SecurityPermissionFlag enumeração para negar e exigir permissões de segurança:

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

Comentários

Cuidado

O CAS (Segurança de Acesso do Código) foi preterido em todas as versões do .NET Framework e do .NET. As versões recentes do .NET não aceitam anotações de CAS e produzem erros caso as APIs relacionadas ao CAS sejam usadas. Os desenvolvedores devem buscar meios alternativos de realizar tarefas de segurança.

Essa enumeração é usada por SecurityPermission.

Cuidado

Muitos desses sinalizadores são poderosos e só devem ser concedidos a códigos altamente confiáveis.

Aplica-se a

Confira também