ContextInformation Class
Collapse the table of content
Expand the table of content

ContextInformation Class

Encapsulates the context information that is associated with a ConfigurationElement object. This class cannot be inherited.

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

public sealed class ContextInformation

The ContextInformation object provides environment details related to an element of the configuration. For instance, you can use the IsMachineLevel property to determine whether a ConfigurationElement was set in Machine.config, or you can determine which hierarchy a ConfigurationElement belongs to by using the HostingContext property.

The following code example demonstrates how to use the ContextInformation type.

#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.ConfigurationSample
  class UsingContextInformation
    static void Main(string[] args)
        // Set the path of the config file.
        string configPath = "";

        // Get the Web application configuration object.
        Configuration config = WebConfigurationManager.OpenWebConfiguration(configPath);

        // Get the section related object.
        HealthMonitoringSection configSection =

        // Display title and info.
        Console.WriteLine("ASP.NET Configuration Info");

        // Display Config details.
        Console.WriteLine("File Path: {0}",
        Console.WriteLine("Section Path: {0}",

          // IsMachineLevel property.
          Console.WriteLine("IsMachineLevel: {0}",

          // Create an object based on HostingContext.
          WebContext myWC =
          // Use the WebContext object to determine 
          // the ApplicationLevel.
          Console.WriteLine("ApplicationLevel: {0}",

      catch (Exception e)
        // 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

Community Additions

© 2015 Microsoft