Export (0) Print
Expand All

XmlSiteMapProvider Class

Note: This class is new in the .NET Framework version 2.0.

The XmlSiteMapProvider class is derived from the SiteMapProvider class and is the default site map provider for ASP.NET. The XmlSiteMapProvider class generates site map trees from XML files.

Namespace: System.Web
Assembly: System.Web (in system.web.dll)

public ref class XmlSiteMapProvider : public StaticSiteMapProvider, IDisposable
public class XmlSiteMapProvider extends StaticSiteMapProvider implements IDisposable
public class XmlSiteMapProvider extends StaticSiteMapProvider implements IDisposable

The XmlSiteMapProvider class loads site map data from an XML file that follows a known schema. The site map data is bounded by <siteMap> tags and consists of nested <siteMapNode> tags. Two constraints are imposed by the SiteMapProvider and XmlSiteMapProvider classes on the structure of the site map data:

  • Only one root node can exist.

  • For SiteMapNode objects that specify URLs, the URLs must be unique within the scope of the provider. (For nodes that do not specify URLs, all keys must be unique.)

The following code example shows an example of an XML file that can be used with the XmlSiteMapProvider.

<siteMap>
  <siteMapNode title="RootNode" description="This is the root node of the site map. There can be only one root node." url="Page1.aspx" >
    <siteMapNode title="ChildofRootNode" description="Descriptions do not have to be unique." url="Page2.aspx">
      <siteMapNode title="ChildOfChildNode" description="SiteMapNode objects can be nested to any level." url="Page3.aspx"/>
    </siteMapNode>
    <siteMapNode title="ChildofRootNode" description="Descriptions do not have to be unique." url="Page4.aspx"/>
  </siteMapNode>
</siteMap>

The XmlSiteMapProvider is the default provider for ASP.NET and it reads XML data from a file named Web.sitemap that is located within the directory structure of the ASP.NET application. By default, the Web.sitemap file is located at the application root; however, if you want to change the name or location of the file from which the XmlSiteMapProvider loads data, you can override the default configuration in your Web.config file. By overriding the default configuration settings in your Web.config file, you can tailor the behavior of the XmlSiteMapProvider for each ASP.NET application, as necessary.

The following code example demonstrates an example Web.config file, where the XmlSiteMapProvider is still used, but a different site map file is used. Because all providers in a SiteMapProviderCollection object must be named uniquely, the one that is specified in the Web.config file uses a name other than the default but is also set as the default provider so that it will be used instead of the XmlSiteMapProvider that is specified in the default ASP.NET configuration.

NoteNote

  You can change the name of the site navigation data file, but you cannot change its extension. The XmlSiteMapProvider only reads data from files that are named with the file name extension .sitemap.

<siteMap defaultProvider="MyXmlSiteMapProvider" enabled="true">
  <providers>
    <add name="MyXmlSiteMapProvider"
      description="SiteMap provider that reads in .sitemap files."
      type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
      siteMapFile="CustomWeb.sitemap" />
  </providers>
</siteMap>
TopicLocation
How to: Programmatically Enumerate Site-Map NodesBuilding ASP .NET Web Applications
How to: Configure Multiple Site Maps and Site-Map ProvidersBuilding ASP .NET Web Applications
How to: Filter the Nodes Retrieved by SiteMapDataSource Web Server ControlsBuilding ASP .NET Web Applications
How to: Display Site-Map Data in Non-Hierarchical Web Server ControlsBuilding ASP .NET Web Applications
How to: Add Simple Site NavigationBuilding ASP .NET Web Applications
How to: Implement ASP.NET Site-Map ProvidersBuilding ASP .NET Web Applications
How to: Programmatically Enumerate Site-Map NodesBuilding ASP .NET Web Applications
How to: Configure Multiple Site Maps and Site-Map ProvidersBuilding ASP .NET Web Applications
How to: Filter the Nodes Retrieved by SiteMapDataSource Web Server ControlsBuilding ASP .NET Web Applications
How to: Display Site-Map Data in Non-Hierarchical Web Server ControlsBuilding ASP .NET Web Applications
How to: Add Simple Site NavigationBuilding ASP .NET Web Applications
How to: Implement ASP.NET Site-Map ProvidersBuilding ASP .NET Web Applications
How to: Add Simple Site NavigationBuilding ASP .NET Web Applications in Visual Studio

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 2000 SP4, 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

Community Additions

ADD
Show:
© 2014 Microsoft