SiteMapPath Web Server Control Overview

The SiteMapPath displays a navigation path (which is also known as a breadcrumb or eyebrow) that shows the user the current page location and displays links as a path back to the home page. The control provides many options for customizing the appearance of the links.

The SiteMapPath control obtains navigation data from a site map. This data includes information about the pages in your Web site, such as the URL, title, description, and location in the navigation hierarchy. Storing your navigation data in one place makes it easier to add and remove items in the navigational menus of your Web site.

In earlier versions of ASP and ASP.NET, when you added a page to your Web site and then added a link to that new page from every other page in the Web site, you had to add the links manually, include a common file, or develop custom navigation functionality. ASP.NET version 2.0 includes navigation controls that make navigational menus easy to create, customize, and maintain.

The following code example shows site-map data that is included in a Web.sitemap file.

<siteMap>
  <siteMapNode title="Home" description="Home" url="~/default.aspx" >
    <siteMapNode title="Services" description="Services we offer" 
      url="~/Services.aspx">
    <siteMapNode title="Training" description="Training classes" 
      url="~/Training.aspx" />
    <siteMapNode title="Consulting" description="Consulting services" 
      url="~/Consulting.aspx" />
    </siteMapNode>
  </siteMapNode>
</siteMap>
NoteNote

Only pages that are listed in the site map can display navigation data in the SiteMapPath control. If you place a SiteMapPath control on a page that is not listed in the site map, the control will display nothing to the client.

You can add a SiteMapPath control to the Training.aspx page by adding the following code.

<asp:SiteMapPath ID="SiteMapPath1" Runat="server"></asp:SiteMapPath>

When the Training.aspx page is viewed by a client, the SiteMapPath control will display something like the following, with Home and Services rendered as hyperlinks:

        Home > Services > Training

You can use the SiteMapPath control to create site navigation without code and without binding data. The control can read and render the site-map information automatically. However, if needed, you can also use the SiteMapPath control to alter site-map data. For more information, see How to: Programmatically Modify Site-Map Nodes in Memory.

The SiteMapPath control allows users to navigate backward — from the current page to pages that are higher in the site hierarchy. However, the SiteMapPath control does not allow you to navigate forward — from the current page to another page that is lower in the site hierarchy. For example, you can use the SiteMapPath control in newsgroup or message board applications to allow users to see the path to the article that they are currently browsing.

See Also

Tasks

How to: Customize the Appearance of SiteMapPath Web Server Controls
How to: Filter the Nodes Retrieved by SiteMapDataSource Web Server Controls

Reference

SiteMapPath
XmlSiteMapProvider

Concepts

ASP.NET Site Navigation Overview
Securing ASP.NET Site Navigation
Securing Data Access

Other Resources

ASP.NET Application Security in Hosted Environments