Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [187]

By Root 5226 0
the equipment of your users, the more likely you will be to raise SEO issues and screen-reader issues for users with disabilities. These are the possible drawbacks of excessive use of JavaScript in the navigation system of a page. Finally, a navigation system should always provide an easy-to-reach link to the home page. A visitor might not land at your site from the main door, so once the user is there, you might want to show him the way to the home page.

In ASP.NET, the site navigation API allows you to define the map of the site and provide a declarative description of how it is laid out. By using the site navigation API, you define the hierarchy of pages you have and group them to form sections and subsections of the site. ASP.NET caches this information and makes it programmatically accessible at run time. With site navigation, you store links to pages in a central location and can optionally bind those links to navigation controls, such as the TreeView and Menu controls. In addition, as mentioned, a link-based map of the site helps search engines considerably.

ASP.NET site navigation offers a number of features, including site maps to describe the logical structure of the site, site map providers to physically store the contents of a map and optional security access rules, and a bunch of controls to display site map information through navigation components. In this section, we discuss how to define, configure, and consume site map information.

Defining Site Map Information


You start by defining the list of constituent pages and relationships between them. Exposed in a standard way, this information then will be easily consumed by site navigation controls and reflected by page output. By default, the site map is expressed through an XML file, usually named web.sitemap. (Thanks to the provider model, however, alternative data sources are possible.)

Site map information is retrieved via the currently selected site map provider. The default site map provider is registered in the root configuration file as an instance of the XmlSiteMapProvider class:

siteMapFile="web.sitemap"

type="System.Web.XmlSiteMapProvider, System.Web, ... " />

As you can see, the schema contains a siteMapFile attribute through which you indicate the name of the source file where site map information can be read from. In spite of the extension, the file must be an XML file validated against a given schema. Note that the XmlSiteMapProvider class doesn’t handle files with an extension other than .sitemap. Finally, note that the XmlSiteMapProvider class detects changes to the site map file and dynamically updates the site map to reflect changes.

Located in the application’s root directory, the web.sitemap file organizes the pages in the site hierarchically. It can reference other site map providers or other site map files in other directories in the same application. Here’s a sample site map file that attempts to describe a Web site to navigate through the contents of the book:

...

...

A site map XML file is composed of a collection of elements rooted in a node. Each page in the Web site is represented with a element. Hierarchies can be created by nesting elements, as in the preceding code snippets. In most cases, the root node contains just one child element, even though this is not a strict rule

Return Main Page Previous Page Next Page

®Online Book Reader