How to skip the root node from the site map in ASP.NET

By default, the site map tree begins with the single root node from the site map. You can decide to skip it in your project, because it introduces a top-level link which might not be very useful. In the example described in the article: How to use the SiteMapPath navigation control in ASP.NET, you may not like the way the home node sticks out. You can clean it by setting the SiteMapDataSource.ShowStartingNode property to false. If you still want to show the Home entry, modify the site map file so it defines the Home node in the first group of pages. The real root node won’t be shown, so it doesn’t need any URL. The next markup lines show the revised Site.master and Web.sitemap files:

Site.master file

<head id=”Head1″ runat=”server”>

<title></title>

<asp:ContentPlaceHolder ID=”head” runat=”server”>

</asp:ContentPlaceHolder>

</head>

<body>

<form id=”form1″ runat=”server”>

<table>

<tr>

<td style=”width: 230px; vertical-align: top;”>

<!– Navigation controls go here. –>

<asp:TreeView ID=”treeNav” runat=”server” DataSourceID=”SiteMapDataSource1″ />

</td>

<td style=”vertical-align: top;”>

<asp:ContentPlaceHolder ID=”ContentPlaceHolder1″ runat=”server” />

</td>

</tr>

</table>

<asp:SiteMapDataSource ID=”SiteMapDataSource1″ runat=”server” ShowStartingNode=”false” />

</form>

</body>

Web.sitemap file

<?xml version=”1.0″ encoding=”utf-8″ ?>

<siteMap xmlns=”http://schemas.microsoft.com/AspNet/SiteMap-File-1.0″ >

<siteMapNode title=”Root” description=”Root” >

<siteMapNode title=”Home” description=”Home” url=”./default.aspx” />

<siteMapNode title=”Web development” description=”Web development” url=”./WebDevelopment.aspx”>

<siteMapNode title=”HTML and CSS” description=”HTML and CSS” url=”./HTMLandCSS.aspx” />

<siteMapNode title=” Scripting” description=”Scripting” url=”./Scripting.aspx” />

</siteMapNode>

 

<siteMapNode title=”Enterprise servers and development” description=” Enterprise servers and development we offer” url=”./EnterpriseSD.aspx”>

<siteMapNode title=”Mail servers” description = “Mail servers” url=”./MailServers.aspx” />

<siteMapNode title=”SQL servers” description=”SQL servers” url=”./SQLServers.aspx” />

<siteMapNode title=”Application servers” description=”Application servers” url=”./ApplicationServers.aspx” />

</siteMapNode>

 

</siteMapNode>

</siteMap>

The next picture shows the result:

 

A site map without the root node

A site map without the root node