二、 使用SiteMap的方式
你可以以三种常见方式来使用在前一节所创建的站点地图文件:
· 使用SiteMapPath控件
· 使用SiteMap数据源控件
· 使用SiteMap类
这个SiteMapPath控件允许你生成breadcrumb。图3显示出什么是breadcrumb。

SiteMapPath控件显示各种层级的导航。例如,你可以点击父或根级别以往回导航或转到顶层。当然,你也可以定制导航层次。
ASP.NET 2.0中还带有一组良好的导航控件,包括TreeView和菜单。借助于SiteMap数据源控件,你可以把站点地图文件与这些控件绑定到一起。
有些情况下,内置的导航控件可能无法满足你的要求。在这种情况中,你可以以编程方式存取这个站点地图文件并且读各种siteMapNode结点。然后,你可以生成一个定制的导航结构—使用siteMapNode的title和URL属性。
三、 使用SiteMapPath控件
在详细讨论细节前,让我们首先创建我们需要的目录结构和Web表单。首先,把两个文件夹Products和Services添加到网站。然后,添加一个新的Master页面MasterPage.master。接着添加显示在表格2中的Web表单,并且确保当你添加它们时都为其设置master页面。
| Web表单名 | 文件夹 |
| Default.aspx | Website root |
| Contact.aspx | Website root |
| Default.aspx | Products |
| Product1.aspx | Products |
| Product2.aspx | Products |
| Default.aspx | Services |
| Service1.aspx | Services |
| Service2.aspx | Services |
现在,打开你前面添加的Master页面。把一个Label控件和一个SiteMapPath控件拖动到它上面。然后,把该Label的Text属性设置为“Welcome!”。
下列的列表显示了MasterPage.master页面中的所有标记:
<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Font-Size="XX-Large" ForeColor="Blue" Text="Welcome!"></asp:Label><br />
<asp:SiteMapPath ID="SiteMapPath1" runat="server"
Font-Names="Verdana" Font-Size="0.8em" PathSeparator=" : ">
<PathSeparatorStyle Font-Bold="True" ForeColor="#5D7B9D" />
<CurrentNodeStyle ForeColor="#333333" />
<NodeStyle Font-Bold="True" ForeColor="#7C6F57" />
<RootNodeStyle Font-Bold="True" ForeColor="#5D7B9D" />
</asp:SiteMapPath>
<br />
<br />
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>
现在,从根文件夹打开Default.aspx。Default.aspx应该看似图4的样子。
CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Font-Size="XX-Large" ForeColor="Blue" Text="Welcome!"></asp:Label><br />
<asp:SiteMapPath ID="SiteMapPath1" runat="server"
Font-Names="Verdana" Font-Size="0.8em" PathSeparator=" : ">
<PathSeparatorStyle Font-Bold="True" ForeColor="#5D7B9D" />
<CurrentNodeStyle ForeColor="#333333" />
<NodeStyle Font-Bold="True" ForeColor="#7C6F57" />
<RootNodeStyle Font-Bold="True" ForeColor="#5D7B9D" />
</asp:SiteMapPath>
<br />
<br />
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
</asp:contentplaceholder>
</div>
</form>
</body>
</html>

