Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

SecurityPermissionFlag Enumeration

Specifies access flags for the security permission object.

This enumeration has a FlagsAttribute attribute that allows a bitwise combination of its member values.

[Visual Basic]
<Flags>
<Serializable>
Public Enum SecurityPermissionFlag
[C#]
[Flags]
[Serializable]
public enum SecurityPermissionFlag
[C++]
[Flags]
[Serializable]
__value public enum SecurityPermissionFlag
[JScript]
public
   Flags
 Serializable
enum SecurityPermissionFlag

Remarks

This enumeration is used by SecurityPermission.

CAUTION   Many of these flags are powerful and should only be granted to highly trusted code.

Members

Member name Description Value
AllFlags The unrestricted state of the permission. 16383
Assertion Ability to assert that all this code's callers have the requisite permission for the operation. 1
BindingRedirects Permission to perform explicit binding redirection in the application configuration file. This includes redirection of .NET Framework assemblies that have been unified as well as other assemblies found outside the .NET Framework. 8192
ControlAppDomain Ability to create and manipulate an AppDomain. 1024
ControlDomainPolicy Ability to specify domain policy. 256
ControlEvidence Ability to provide evidence, including the ability to alter the evidence provided by the common language runtime.

This is a powerful permission that should only be granted to highly trusted code.

32
ControlPolicy Ability to view and modify policy.

This is a powerful permission that should only be granted to highly trusted code.

64
ControlPrincipal Ability to manipulate the principal object. 512
ControlThread Ability to use certain advanced operations on threads. 16
Execution Permission for the code to run. Without this permission, managed code will not be executed.

This flag has no effect when used dynamically with stack modifiers such as Deny, Assert, and PermitOnly.

8
Infrastructure Permission to plug code into the common language runtime infrastructure, such as adding Remoting Context Sinks, Envoy Sinks and Dynamic Sinks. 4096
NoFlags No security access. 0
RemotingConfiguration Permission to configure Remoting types and channels. 2048
SerializationFormatter Ability to provide serialization services. Used by serialization formatters. 128
SkipVerification Ability to skip verification of code in this assembly. Code that is unverifiable can be run if this permission is granted.

This is a powerful permission that should be granted only to highly trusted code.

This flag has no effect when used dynamically with stack modifiers such as Deny, Assert, and PermitOnly.

4
UnmanagedCode Ability to call unmanaged code.

Since unmanaged code potentially allows other permissions to be bypassed, this is a dangerous permission that should only be granted to highly trusted code. It is used for such applications as calling native code using PInvoke or using COM interop.

2

Example

[Visual Basic] 
' This class generates SecurityPermission objects using SecurityPermissionFlag enumeration values.

Imports System
Imports System.Security
Imports System.Security.Permissions
Imports Microsoft.VisualBasic

Public Class SecurityGenerator


    Private mySecurity As SecurityPermissionFlag() = {SecurityPermissionFlag.AllFlags, _
        SecurityPermissionFlag.Assertion, SecurityPermissionFlag.ControlAppDomain, _
        SecurityPermissionFlag.ControlDomainPolicy, SecurityPermissionFlag.ControlEvidence, _
        SecurityPermissionFlag.ControlPolicy, SecurityPermissionFlag.ControlPrincipal, _
        SecurityPermissionFlag.ControlThread, SecurityPermissionFlag.Execution, _
        SecurityPermissionFlag.Infrastructure, SecurityPermissionFlag.NoFlags, _
        SecurityPermissionFlag.RemotingConfiguration, _
        SecurityPermissionFlag.SerializationFormatter, _
        SecurityPermissionFlag.SkipVerification, _
        SecurityPermissionFlag.UnmanagedCode}

    Private reflectionIndex As Integer = 0


    Public Sub New()
        ResetIndex()
    End Sub 'New


    Public Sub ResetIndex()
        reflectionIndex = 0
    End Sub 'ResetIndex

    ' CreateSecurity creates a SecurityPermission object.
    Public Function CreateSecurity(ByRef SecurityPerm As SecurityPermission, _
        ByRef Security As SecurityPermissionFlag) As Boolean

        If reflectionIndex >= mySecurity.Length Then
            SecurityPerm = New SecurityPermission(PermissionState.None)
            Security = SecurityPermissionFlag.NoFlags
            reflectionIndex &= 1
            Return False
        End If
        Security = mySecurity(reflectionIndex)
        reflectionIndex = reflectionIndex + 1
        Try
            SecurityPerm = New SecurityPermission(Security)
            Return True
        Catch e As Exception
            Console.WriteLine(("Cannot create SecurityPermission: " & Security & " " & e.ToString()))
            SecurityPerm = New SecurityPermission(PermissionState.None)
            Security = SecurityPermissionFlag.NoFlags
            Return True
        End Try
    End Function 'CreateSecurity
End Class 'SecurityGenerator 
' End of SecurityGenerator.

[C#] 

// This class generates SecurityPermission objects using SecurityPermissionFlag enumeration values.

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

public  class SecurityGenerator
{

    private SecurityPermissionFlag[] mySecurity = 
        {
                SecurityPermissionFlag.AllFlags,
            SecurityPermissionFlag.Assertion,
            SecurityPermissionFlag.ControlAppDomain,
            SecurityPermissionFlag.ControlDomainPolicy,
            SecurityPermissionFlag.ControlEvidence,
            SecurityPermissionFlag.ControlPolicy,
            SecurityPermissionFlag.ControlPrincipal,
            SecurityPermissionFlag.ControlThread,
            SecurityPermissionFlag.Execution,
            SecurityPermissionFlag.Infrastructure,
            SecurityPermissionFlag.NoFlags,
            SecurityPermissionFlag.RemotingConfiguration,
            SecurityPermissionFlag.SerializationFormatter,
            SecurityPermissionFlag.SkipVerification,
            SecurityPermissionFlag.UnmanagedCode};

    private int reflectionIndex = 0;

    public SecurityGenerator()
    {
        ResetIndex();
    }

    public void ResetIndex()
    {
        reflectionIndex = 0;
    }
    // CreateSecurity creates a SecurityPermission object.
    public bool CreateSecurity(out SecurityPermission SecurityPerm, out SecurityPermissionFlag Security)
    {

        if(reflectionIndex >= mySecurity.Length) 
        {
            SecurityPerm = new SecurityPermission(PermissionState.None);
            Security=SecurityPermissionFlag.NoFlags;
            reflectionIndex++;
            return false;
        }
        Security = mySecurity[reflectionIndex++];
        try
        {
            SecurityPerm = new SecurityPermission(Security);
            return true;
        } 
        catch(Exception e)
        {
            Console.WriteLine("Cannot create SecurityPermission: " + Security +" "+e);
            SecurityPerm = new SecurityPermission(PermissionState.None);
            Security=SecurityPermissionFlag.NoFlags;
            return true;
        }
    }
} // End of SecurityGenerator.

[C++] 

// This class generates SecurityPermission objects using SecurityPermissionFlag enumeration values.

#using <mscorlib.dll>

using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Runtime::InteropServices;

public __gc class SecurityGenerator {

private:
   SecurityPermissionFlag mySecurity[];
   int  reflectionIndex;

public:
   SecurityGenerator() {
      SecurityPermissionFlag temp[] = {
         SecurityPermissionFlag::AllFlags,
         SecurityPermissionFlag::Assertion,
         SecurityPermissionFlag::ControlAppDomain,
         SecurityPermissionFlag::ControlDomainPolicy,
         SecurityPermissionFlag::ControlEvidence,
         SecurityPermissionFlag::ControlPolicy,
         SecurityPermissionFlag::ControlPrincipal,
         SecurityPermissionFlag::ControlThread,
         SecurityPermissionFlag::Execution,
         SecurityPermissionFlag::Infrastructure,
         SecurityPermissionFlag::NoFlags,
         SecurityPermissionFlag::RemotingConfiguration,
         SecurityPermissionFlag::SerializationFormatter,
         SecurityPermissionFlag::SkipVerification,
         SecurityPermissionFlag::UnmanagedCode};
      mySecurity = temp;
      ResetIndex();
   }

public:
   void ResetIndex() {
      reflectionIndex = 0;
   }
   // CreateSecurity creates a SecurityPermission Object*.
public:
   bool CreateSecurity([Out] SecurityPermission** SecurityPerm, [Out] SecurityPermissionFlag* Security) {
      if (reflectionIndex >= mySecurity->Length) {
         *SecurityPerm = new SecurityPermission(PermissionState::None);
         *Security=SecurityPermissionFlag::NoFlags;
         reflectionIndex++;
         return false;
      }
      *Security = mySecurity[reflectionIndex++];
      try {
         *SecurityPerm = new SecurityPermission(*Security);
         return true;
      } catch (Exception* e) {
         Console::WriteLine(S"Cannot create SecurityPermission: {0}{1}", __box(*Security), e);
         *SecurityPerm = new SecurityPermission(PermissionState::None);
         *Security=SecurityPermissionFlag::NoFlags;
         return true;
      }
   }
}; // End of SecurityGenerator.

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Security.Permissions

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

Assembly: Mscorlib (in Mscorlib.dll)

See Also

System.Security.Permissions Namespace | SecurityPermission | SecurityPermissionAttribute

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft