Understanding Site Maps


Before you learn about the navigation controls, you first need to understand Site Maps. All three navigation controls use Site Maps to retrieve navigation information. A Site Map enables you to represent the navigational relationships between the pages in an application, independent of the actual physical relationship between pages as stored in the file system.

Site Maps use the provider model. In the next chapter, you learn how to create custom Site Map providers to store Site Maps in custom data stores such as database tables. The examples in this chapter take advantage of the default XML Site Map provider, which enables you to store a Site Map in an XML file.

By default, the navigation controls assume the existence of an XML file named Web.sitemap, which is located in the root of your application.

For example, Listing 17.1 contains a simple Site Map.

Listing 17.1. Web.sitemap

<?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode   url="~/Default.aspx"   title="Home"   description="The home page of the Website">   <!-- Product Nodes -->   <siteMapNode     title="Products"     description="Website products">     <siteMapNode       url="~/Products/FirstProduct.aspx"       title="First Product"       description="The first product" />     <siteMapNode       url="~/Products/SecondProduct.aspx"       title="Second Product"       description="The second product" />   </siteMapNode>     <!-- Services Nodes -->     <siteMapNode       title="Services"       description="Website services">       <siteMapNode         url="~/Service/FirstService.aspx"         title="First Service"         description="The first service" />       <siteMapNode         url="~/Products/SecondService.aspx"         title="Second Service"         description="The second service" />     </siteMapNode>     </siteMapNode> </siteMapNode> </siteMap>

A Site Map file contains <siteMapNode> elements. There can be only one top-level node. In the case of Listing 17.1, the top-level node represents the website's homepage.

A <siteMapNode> supports three main attributes:

  • title A brief title that you want to associate with a node.

  • description A longer description that you want to associate with a node.

  • url A URL that points to a page or other resource.

Notice that the url attribute is not required. Both the Products and Services nodes do not include a url attribute because these nodes do not represent pages to which you can navigate.

Each <siteMapNode> can contain any number of child nodes. In Listing 17.1, both the Products and Services nodes include two child nodes.

The Site Map in Listing 17.1 represents a website that has the following folder and page structure:

Default.aspx Products   FirstProduct.aspx   SecondProduct.aspx Services   FirstService.aspx   SecondService.aspx 


The navigational structure of a website as represented by a Site Map is not required to have any relationship to the navigational structure of a website as stored in the file system. You can create any relationship between the nodes in a Site Map that you want.




ASP. NET 2.0 Unleashed
ASP.NET 2.0 Unleashed
ISBN: 0672328232
EAN: 2147483647
Year: 2006
Pages: 276

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net