This documentation is archived and is not being maintained.

TrustLevelCollection Class

Contains a collection of TrustLevel objects. This class cannot be inherited.

Namespace:  System.Web.Configuration
Assembly:  System.Web (in System.Web.dll)

[ConfigurationCollectionAttribute(typeof(TrustLevel), AddItemName = "trustLevel", 
	CollectionType = ConfigurationElementCollectionType.BasicMap)]
public sealed class TrustLevelCollection : ConfigurationElementCollection

TrustLevel objects are used to map specific security levels to named policy files.

The following code example demonstrates how to use the TrustLevelCollection class.

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Web;
using System.Web.Configuration;


namespace Samples.Aspnet.SystemWebConfiguration
  class UsingTrustLevelCollection
    static void Main(string[] args)
        // Display title.
        Console.WriteLine("ASP.NET TrustLevelCollection Info");

        // Instantiate a new TrustLevelCollection object.
        TrustLevelCollection TrustLevelCollection1 = 
          new TrustLevelCollection();

        // Add a new TrustLevel to the collection.
        TrustLevelCollection1.Add(new TrustLevel("Level1", "Level1.config"));

        // Create a new TrustLevel object.
        TrustLevel TrustLevel2 = 
          new TrustLevel("Level2", "Level2.config");

        // Set the TrustLevel object within the collection.
        TrustLevelCollection1.Set(1, TrustLevel2);

        // Display item details of the collection. 
        for (int i = 0; i < TrustLevelCollection1.Count; i++)
          Console.WriteLine("Collection item {0}", i);
          Console.WriteLine("Name: {0}", 
          Console.WriteLine("PolicyFile: {0}", 

      catch (Exception e)
        // Unknown error.

      // Display and wait.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

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

.NET Framework

Supported in: 3.5, 3.0, 2.0