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.

4 Comments

  • it helped a lot thanks
    i got my mistake rectified

  • I had this painful problem too, the quicker way to re-use the same URL is put a #1 after it, then to reuse the same URL put a #2 etc on the second use of and so on.

  • Thanks a lot.
    This helped me to solve the exception of Multiple nodes

  • I know this has been a long time since some one posted here but I thought I would try.

    Putting #1 on the end only half fixes the problem. The error is gone but when you navigate to page with #1, the breadcrumb shows the first link in the web.sitemap and not the correct path.

Comments have been disabled for this content.