Online Book Reader

Home Category

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

By Root 5702 0
hard-coded in the schema of the XML file. All URLs linked from the site map file should belong to the same application using the file. Also in this case, though, exceptions are acceptable. In other words, you are allowed to specify links to pages in other applications, but the site navigation API won’t check these links. As long as links belong to the same application, the API can verify them and return design-time errors if there are broken links.

Table 8-4 lists the feasible attributes of the element.

Table 8-4. Attributes of the Element

Attribute

Description

description

Defines the text used to describe the page. This text is used to add a ToolTip to the page link in a SiteMapPath control (discussed later) and as documentation.

provider

String that indicates the site map provider to use to fill the current node.

resourceKey

Indicates the name of the resource key used to localize a given node of the site map.

roles

String that indicates the roles that users must have to view this page.

siteMapFile

Indicates the name of the site map file to use to fill the current node.

title

Defines the text used as the text of the link to the page.

url

Defines the URL of the page.

The roles attribute is key to implementing a feature known as security trimming. Security trimming essentially refers to the site map API capability of preventing unauthorized users from viewing pages that require a particular role.

In addition to using the attributes listed in Table 8-4, you can use custom attributes too. You cannot use custom nodes. A .sitemap file can contain only elements and a root node.

Site Map Providers


The site navigation subsystem is provider based, meaning that you can use custom providers to define some site map contents. A custom site map provider reads information from a different storage medium, be it another XML file with a distinct schema, a text file or, perhaps, a database. A custom site map provider is a class that inherits from SiteMapProvider or, better yet, from an intermediate class named StaticSiteMapProvider.

Note that you can optionally use multiple providers at the same time. For example, by setting the provider attribute on a node, you instruct the site map subsystem to use that site map provider to retrieve nodes to insert at that point of the hierarchy.

...

The additional provider must be registered in the configuration file and feature all information needed to connect to its own data source. Here’s an example for the sample text file provider:

type="SimpleTextSiteMapProvider, Samples"

siteMapFile="MySiteMap.txt" />

The linked to the SimpleTextSiteMapProvider component will contain all the nodes as defined in the MySiteMap.txt file. Reading and parsing to nodes any information in MySiteMap.txt is the responsibility of the custom provider. As a result, you have a site map file that uses two providers at the same time: the default XmlSiteMapProvider and the custom SimpleTextSiteMapProvider.

Creating the map of a site is only the first step. Once it is created, in fact, this information must be easily and programmatically accessible. Although most of the time you consume site information through a bunch of ad hoc controls, it’s useful to take a look at the class that acts as the official container of site map information—the SiteMap class. When an ASP.NET application runs, the site map structure is exposed through a global instance of the SiteMap class.

The SiteMap Class


Defined in the System.Web assembly and namespace, the SiteMap class has only static members. It exposes a

Return Main Page Previous Page Next Page

®Online Book Reader