SiteMap nodes and identical urls - Raj Kaimal

SiteMap nodes and identical urls

The XMLSiteMapProvider will throw an exception if you have multiple SiteMapNodes with the same URL in your Web.sitemap file. For example, the following

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode>
    <siteMapNode url=
"~/Employee/Home.aspx" title="Employee Home">
      <siteMapNode url="~/Common/Records.aspx" title="Records"/>
      <siteMapNode url="~/Employee/Profile.aspx" title="Profile" />
    </siteMapNode>
    <siteMapNode url=
"~/Admin/Home.aspx" title="Admin Home">
      <siteMapNode url="~/Common/Records.aspx" title="Records"/>
      <siteMapNode url="~/Admin/Profile.aspx" title="Profile" />
    </siteMapNode>
  </siteMapNode
>
</siteMap>

will fail with the following error

Multiple nodes with the same URL '/Navigation/Common/Records.aspx' were found. XmlSiteMapProvider requires that sitemap nodes have unique URLs.

The simple workaround I came up with is to move all the contents of Records.aspx to a UserControl and have two aspx pages with unique names load this UserControl. So my sitemap file becomes:


      <siteMapNode url="~/Common/EmployeeRecords.aspx" title="Records"/>

      <siteMapNode url="~/Common/AdminRecords.aspx" title="Records"/>


ScottGu suggests that another (maybe easier) way to-do it is to have one of the .aspx files have a querystring attribute to it in the sitemap (for example: Records.aspx?param=1). The site navigation system allows you to differentiate using querystrings and will allow this.

A different approach as suggested by Danny Chen is that if you wanted to, since there is no requirement on the actual SiteMapProvider, you could write your own custom provider or possibly inherit from the XmlSiteMapProvider and override key functions (like AddNode, FindSiteMapNode) to get the behavior you're looking for.

Published Monday, November 21, 2005 9:10 PM by rajbk
Filed under:

Comments

# re: SiteMap nodes and identical urls

Or similar to query string you can just add # at the end. Something like this:

<siteMapNode url="~/Common/Records.aspx"/>

<siteMapNode url="~/Common/Records.aspx"#/>

Thursday, February 21, 2008 9:47 PM by kkcode

# re: SiteMap nodes and identical urls

And with VS2008, we still have this stupid problem.  Thanks for documenting it.

Friday, March 28, 2008 10:10 PM by chris lively

# 6 Tweaks for your ASP:Menu Control

Prologue I have slowly been working on redesigning recreating our company website in all ASP.Net 2.0.

Thursday, September 11, 2008 12:55 PM by .Net Discoveries

Leave a Comment

(required) 
(required) 
(optional)
(required)