
Navigator : Home > Tutorials > Website Navigation Tutorials > ...
Introduction to Using the Sitemap
Discusses the benefits and uses of the Site Map in the ASP.NET framework. The Site Map is a hierarchical listing of web pages on your web site. This information is listed inside the Web.sitemap file in an XML format that can be displayed on any aspx page with the correct controls.
In this tutorial, we will discuss the benefits and uses of the Site Map in the ASP.NET framework. The Site Map is a hierarchical listing of web pages on your web site. This information is listed inside the Web.sitemap file in an XML format that can be displayed on any aspx page with the correct controls.
Try Server Intellect for Windows Server Hosting. Quality and Quantity!
First you can open a Web Application in Visual Studio 2008. Now add a new Item and choose the Site Map. Visual Studio will automatically name it Web.sitemap and start a few siteMap nodes for you as seen below.
<?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode url="" title="" description=""> <siteMapNode url="" title="" description="" /> </siteMapNode> </siteMap> |
Notice the XML declaration at the top of the file. Every node must be listed inside of the parent <siteMap> tags. Inside of the <siteMap> tags you can list as many <siteMapNode> tags as you'd like as well as nest them if necessary.
In general the Site Map must consist of internal URLs, if it does contain external URLs settings must be adjusted for it to be visible to the end user.
Now that our Site Map has been created, we need a way to display it to the web site visitor. ASP.NET contains several controls to display the Site Map. We can first start out with the most basic control by using the <asp:SiteMapPath> tag. An example is listed below.
| <asp:SiteMapPath ID="SiteMapPath1" Runat="server" /> |
This will display a nested horizontal output with the current page listed farthest to the right followed by each parent to its left. It should look something along the lines of Home > Directory Listing > John Smith. Each node except the current page will be hyperlinked.
Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.
I'll list a few more advanced controls below.
|
<asp:SiteMapDataSource ID="SiteMapDataSource1" Runat="server" />
<asp:TreeView ID="TreeView1" Runat="Server" DataSourceID="SiteMapDataSource1" />
<asp:Menu ID="Menu2" Runat="server" DataSourceID="SiteMapDataSource1" /> |
Notice the <asp:SiteMapDataSource> tag is referenced in each of the following controls. It is necessary to display the Site Map with those controls. The <asp:TreeView> control displays the parent node at the top with each child in hideable DIVs below it. The <asp:Menu> control horizontally hides each child node until the visitor hovers over its parent node. This control has several attributes which will prevent the child nodes from being hidden so that the visitor doesn't have to hover over the parent node first. Obviously each node with the exception of the current page hyperlinks to itself.
These are the basics on how to use the ASP.NET Site Map abilities. The Web.sitemap file can be located in other directories, but must be referenced if used. You can also add nodes to the Site Map without editing the Web.sitemap file with C# or VB.NET programming.
Looking for more .NET Tutorials? Click Here!