The three navigation Web server controls, SiteMapPath, Menu, and TreeView, can work with an XML site map that you provide for your Web site, or a site map provided in a different format if you implement an alternative site map provider. Once you have created such a data source, these navigation Web server controls are able to automatically generate location and navigation information for users.
You see an example XML site map shortly.
You can also use a Treeview control to display other structured data, but it really comes into its own with site maps, and gives you an alternative view of navigation information. The navigation Web server controls are shown in the following table.
To provide a site map XML file for your site, you can add a site map file (. sitemap) using the Web site ¢ Add New Item menu item, You link to site maps via providers. The default XML provider looks for a file called Web. sitemap in the root of your site, so unless you are going to use a different provider, you should accept the default file name supplied.
A site map XML file contains a root <siteMap> element containing a single <siteMapNode> element,
which in turn can contain any number of nested <siteMapNode> elements. Each <si teMapNode> element uses the attributes shown in the following table.
Once a site has a Web. si temap file, adding a breadcrumb trail is as simple as putting the following code on your page:
<asp:SiteMapPath ID=”SiteMapPathl” Runat=”server’ />
This will use the default provider and the current URL location to format a list of links to parent pages.
Adding a menu or tree view menu requires a SiteMapDataSource control, but again this can be very simple:
<asp:SiteMapDataSource ID=”SiteMapDataSourcel” Runat=’server” />
When using a custom provider, the only difference is that you can supply the provider 10 via a Si teMapProvider attribute. You can also remove upper levels of the menu data (such as the root Home item) using StartingNodeOffset; remove just the top-level link using ShowStartingNode=False startfrom the current location using StartFromCurrentNode= ‘True’; and override the root node using StartingNodeUrl.
The data from this data source is consumed by Menu and Treeview controls simply by setting their Data Source to the ID of the SitemapDataSource. Both controls include numerous styling properties and can be them.
Navigatlon In PCSDemoSite
The sitemap for PCSDemoSite is as follows:
The PCSDemoSite Web siteuses a custom provider to obtain information from web. sitemap – which is necessary because the default provider ignores the roles attributes.The provider is defined-in the Web. config fit for the Web site as follows:
The only difference between this and the default provider is the addition of securityTrimmingEnabled=,true’ r which instructstileprovider to supply data for just those nodes that this current user is allowed to see, This visibilityisdetermined by the role membership of the user, as you see in the next section.
The MasterPage. master page in PCSDemoSite includes siteMapPath and TreeView navigation displays along with a data source, as follows:
The only point to note here is that CSSclasses are supplied for both SitePath and TreeView, to facilitate them,