Export (0) Print
Expand All

PolicyLevelType Enumeration

Specifies the type of a managed code policy level.

Namespace: System.Security
Assembly: mscorlib (in mscorlib.dll)

[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum class PolicyLevelType
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum PolicyLevelType
SerializableAttribute 
ComVisibleAttribute(true) 
public enum PolicyLevelType

 Member nameDescription
AppDomainSecurity policy for all managed code in an application. 
EnterpriseSecurity policy for all managed code in an enterprise. 
MachineSecurity policy for all managed code that is run on the computer. 
UserSecurity policy for all managed code that is run by the user. 

The highest level of security policy is enterprise-wide. Successive lower levels of hierarchy represent further policy restrictions, but can never grant more permissions than allowed by higher levels. The policy levels in order are the following.

1. Enterprise

2. Machine

3. User

4. Application domain

This example shows how to use the PolicyLevelType enumeration to query information from the code access security administration settings.

using namespace System;
using namespace System::Collections;
using namespace System::Security;
using namespace System::Security::Policy;

// This helper method returns a PolicyLevel that corresponds to
// the specified PolicyLevelType.
PolicyLevel^ GetPolicyLevel(PolicyLevelType policyLevelType)
{
    IEnumerator^ policyLevels = SecurityManager::PolicyHierarchy();

    // Map the policy level type to the policy level collection.
    int levelCount = 0;
    switch (policyLevelType)
    {
    case PolicyLevelType::Enterprise: levelCount = 0; break;
    case PolicyLevelType::Machine: levelCount = 1; break;
    case PolicyLevelType::User: levelCount = 2; break;
    case PolicyLevelType::AppDomain: levelCount = 3; break;
    }

    for (; levelCount >= 0; levelCount--)
    {
        policyLevels->MoveNext();
    }

    return (PolicyLevel^) policyLevels->Current;
}

void DisplayIntranetZonePermissionSetForPolicyLevel(
    PolicyLevelType policyLevelType)
{
    // Create an Evidence object that contains the intranet zone.
    Evidence^ intranetEvidence = gcnew Evidence();
    intranetEvidence->AddHost(gcnew Zone(SecurityZone::Intranet));
    // Get the policy level for the specified policy level type and then
    // resolve the evidence against it to get the policy statement.
    PolicyStatement^ resolvedPolicy = GetPolicyLevel(policyLevelType)->
        Resolve(intranetEvidence);

    // Show the calculated policy statement.
    Console::WriteLine(
        "---> Intranet zone permission set for {0} policy level:",
        policyLevelType);
    Console::WriteLine(resolvedPolicy->PermissionSet);
}

int main()
{
    DisplayIntranetZonePermissionSetForPolicyLevel(PolicyLevelType::User);
    Console::WriteLine();
    DisplayIntranetZonePermissionSetForPolicyLevel(PolicyLevelType::Machine);
}

// This code produces the following output.
//
// ---> Intranet Zone permission set for User policy level:
// <PermissionSet class="System.Security.PermissionSet"
// version="1"
// Unrestricted="true"/>
// ---> Intranet Zone permission set for Machine policy level:
// <PermissionSet class="System.Security.PermissionSet"
// version="1">
// <IPermission class="System.Security.Permissions.EnvironmentPermission,
// mscorlib, 
// Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
// version="1"
// Read="USERNAME"/>
// <IPermission class="System.Security.Permissions.FileDialogPermission,
// mscorlib, 
// Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
// version="1"
// Unrestricted="true"/>
// <IPermission class=
// "System.Security.Permissions.IsolatedStorageFilePermission, mscorlib,
// Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
// version="1"
// Allowed="AssemblyIsolationByUser"
// UserQuota="9223372036854775807"
// Expiry="9223372036854775807"
// Permanent="True"/>
// <IPermission class="System.Security.Permissions.ReflectionPermission,
// mscorlib,
// Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
// version="1"
// Flags="ReflectionEmit"/>
// <IPermission class="System.Security.Permissions.SecurityPermission,
// mscorlib,
// Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
// version="1"
// Flags="Assertion, Execution, BindingRedirects"/>
// <IPermission class="System.Security.Permissions.UIPermission, mscorlib,
// Version=2.0.3600.0, 
// Culture=neutral, PublicKeyToken=b77a5c561934e089"
// version="1"
// Unrestricted="true"/>
// <IPermission class="System.Net.DnsPermission, System, Version=2.0.3600.0,
// Culture=neutral, 
// PublicKeyToken=b77a5c561934e089"
// version="1"
// Unrestricted="true"/>
// <IPermission class="System.Windows.Forms.WebBrowserPermission, System,
// Version=2.0.3600.0, 
// Culture=neutral, PublicKeyToken=b77a5c561934e089"
// version="1"
// Level="Restricted"/>
// <IPermission class="System.Drawing.Printing.PrintingPermission,
// System.Drawing,
// Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
// version="1"
// Level="DefaultPrinting"/>
// <IPermission class="System.Diagnostics.EventLogPermission, System,
// Version=2.0.3600.0,
// Culture=neutral, PublicKeyToken=b77a5c561934e089"
// version="1">
// <Machine name="."
// access="Instrument"/>
// </IPermission>
// </PermissionSet>

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft