Export (0) Print
Expand All
2 out of 2 rated this helpful - Rate this topic

SiteMapSection Class

Defines configuration settings that are used to support the infrastructure for configuring, storing, and rendering site navigation. This class cannot be inherited.

Namespace: System.Web.Configuration
Assembly: System.Web (in system.web.dll)
public sealed class SiteMapSection : ConfigurationSection
public final class SiteMapSection extends ConfigurationSection
public final class SiteMapSection extends ConfigurationSection
Not applicable.

The SiteMapSection class provides a way to programmatically access and modify the content of the configuration file siteMap section.

This example demonstrates how to specify values declaratively for several attributes of the siteMap section, which can also be accessed as members of the SiteMapSection class.

The following configuration file example shows how to specify values declaratively for the siteMap section.

<system.web>
  <siteMap defaultProvider="XmlSiteMapReader" enabled="true">
    <providers>
      <clear />
      <add 
        name="XmlSiteMapReader"
        type="XmlSiteMapProvider, System.Web, Version=1.1.3300.0,
              Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        siteMapFile="my.sitemap" 
        description="XmlSiteMapProvider that loads my.sitemap"/>
  </siteMap>
</system.web>

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

#region Using directives

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

#endregion

namespace Samples.Aspnet.SystemWebConfiguration
{
  class UsingSiteMapSection
  {
    static void Main(string[] args)
    {
      try
      {
        // 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.
        SiteMapSection configSection = 
          (SiteMapSection)config.GetSection("system.web/siteMap");

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

        // Display Config details.
        Console.WriteLine("File Path: {0}", 
          config.FilePath);
        Console.WriteLine("Section Path: {0}",
          configSection.SectionInformation.Name);
        // Display Default Provider.
        Console.WriteLine("Default Provider: {0}",
          configSection.DefaultProvider);

        // Set Default Provider.
        configSection.DefaultProvider = 
          "SiteMapProviderName";

        // Display Enabled value.
        Console.WriteLine("Enabled: {0}", configSection.Enabled);

        // Set Enabled value.
        configSection.Enabled = true;

        // Display the number of Providers
        Console.WriteLine("Providers Collection Count: {0}",
          configSection.Providers.Count);

        // Display elements of the Providers collection property.
        foreach (ProviderSettings providerItem in configSection.Providers)
        {
          Console.WriteLine();
          Console.WriteLine("Provider Details:");
          Console.WriteLine("Name: {0}", providerItem.Name);
          Console.WriteLine("Type: {0}", providerItem.Type);
        }

        // Update if not locked.
        if (!configSection.SectionInformation.IsLocked)
        {
          config.Save();
          Console.WriteLine("** Configuration updated.");
        }
        else
        {
          Console.WriteLine("** Could not update, section is locked.");
        }
      }

      catch (Exception e)
      {
        // Unknown error.
        Console.WriteLine(e.ToString());
      }

      // Display and wait
      Console.ReadLine();
    }
  }
}

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 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.