Team LiB
Previous Section Next Section

Chapter 5: Integrating Site Navigation

Be honest, now: Did you ever make a web site without navigation? OK, maybe apart from one or two little test projects. Anyway, any web site that consists of more than two or three pages needs navigation.

The second version of ASP.NET offers special features for implementing navigation elements. In this chapter I present these new features to you.

Defining a Site Map

ASP.NET's integrated support for defining a site map is based on an XML file named app.sitemap, which is placed in the root directory of the application. The structure of the file complies with a specific schema:

   <siteMapNode title="" description="" url="">
      <siteMapNode .../>

Every single siteMapNode element included in this schema can be nested and results in the hierarchy of the navigation. The documentation presents one example for such a hierarchy, which Listing 5-1 shows.

Listing 5-1: App.sitemap Contains an XML-Formatted Site Map Hierarchy
Start example
<?xml version="1.0" encoding="utf-8" ?>
   <siteMapNode title="Home" description="Home" url="default.aspx" >
      <siteMapNode title="Products" description="Our products"
          <siteMapNode title="Hardware" description="Hardware choices"
               url="navigation1.aspx" />
          <siteMapNode title="Software" description="Software choices"
               url="Software.aspx" />
      <siteMapNode title="Services" description="Services we offer"
         <siteMapNode title="Training" description="Training classes"
             url="Training.aspx" />
         <siteMapNode title="Consulting" description="Consulting services"
             url="Consulting.aspx" />
         <siteMapNode title="Support" description="Supports plans"
             url="Support.aspx" />
End example

The two areas, "Products" and "Services," are placed below "Home" and have some submenus themselves. Please note that the structures being used here don't have to correspond with the physical structure of your files and directories. But it can be quite easy to define the navigation by the file structure and vice versa. Particularly with large projects, you'll get a much better overview this way.

Apart from the attributes title, url, and description, you may additionally allocate keywords to a list of keywords for each individual page. Multiple keywords are separated by commas. If you intend to give only limited access to a page, or rather the navigation item itself, you must pass the permitted roles to the attribute roles. Don't forget to use commas to separate the roles. I explain the use of the new user management features later in Chapter 6. By the way, you may place any individual attributes here as well.

If you want to allocate this (or a different) navigation to your application, you should keep on reading. Add a new XML file with the previously mentioned name, app.sitemap, to your project and copy the content shown in Listing 5-1 into it.

Team LiB
Previous Section Next Section