Поделиться через


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.

This topic contains:

  • Background

  • Code Examples

  • Class Reference

Background

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 navigation data in one place makes it easier to add and remove items in the navigational menus of a Web site.

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>

Note

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 in the browser, the SiteMapPath control displays 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 enables users to navigate backward — from the current page to pages that are higher in the site hierarchy. However, the SiteMapPath control does not enable users 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 enable users to see the path to the article that they are currently browsing.

Code Examples

How to: Add Simple Site Navigation

How to: Customize the Appearance of SiteMapPath Web Server Controls

How to: Configure Multiple Site Maps and Site-Map Providers

Back to top

Class Reference

The following table lists the classes that relate to the SiteMapPath control.

Member

Description

SiteMapPath

The main class for the control.

Back to top

See Also

Tasks

How to: Customize the Appearance of SiteMapPath Web Server Controls

How to: Filter the Nodes Retrieved by SiteMapDataSource Web Server Controls

Concepts

ASP.NET Site Navigation Overview

Securing ASP.NET Site Navigation

Securing Data Access

Reference

SiteMapPath

XmlSiteMapProvider

Other Resources

ASP.NET Application Security in Hosted Environments