SiteMapPath Disappears on sub page

2.6k Views Asked by At

For some reason on my page my SiteMapPath disappears.

Site structure:

WebApp
-Default.aspx
-> Reports\
----Default.aspx
----MyReport.aspx

Web.sitemap

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="~/Default.aspx" title="Overview"  description="Overview">
    <siteMapNode url="~/Reports/Default.aspx" title="Reports"  description="Reports" >
      <siteMapNode url="~/Reports/MyReport.aspx" title="MyReport"  description="MyReport" />
    </siteMapNode>
  </siteMapNode>
</siteMap>

The SiteMapPath will display when I'm on the overview page of the reports page but not the MyReport page. With the sitemap bound to a treeview I see all of my nodes correctly.

Works - shows me on MyReport Page

<asp:TreeView ID="TreeView1" runat="Server" DataSourceID="SitePathDataSource">
</asp:TreeView>

Disappears on MyReport Page but visible on all others

<asp:SiteMapPath ID="SiteMapPath1" runat="server" DataSourceID="SitePathDataSource">
</asp:SiteMapPath>
3

There are 3 best solutions below

2
On

I'm not exactly an expert on this. I did just test it on my pages and it worked fine. The only difference between what I am doing and yours is I am not specifying a filename on the parent node. Although I kind of stumbled into that one because I couldn't have the same path twice in my sitemap.

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >  
    <siteMapNode url="~/Default.aspx" title="Overview"  description="Overview">   
        <siteMapNode url="~/Reports/" title="Reports"  description="Reports" >      
            <siteMapNode url="~/Reports/Default.aspx" title="Reports Home"  description="Home" />
            <siteMapNode url="~/Reports/MyReport.aspx" title="MyReport"  description="MyReport" />    
        </siteMapNode>  
    </siteMapNode>
</siteMap>
0
On

What is the URL in your browser when the control is not displayed? I'd bet that you have a querystring value or something that does not match Reports/Myreport.aspx. If the path of the page does not match an item exactly in the sitemapnode it won't display.

0
On

Assign sitemap provider in page_load of page

SiteMapPath1.SiteMapProvider = "DefaultSiteMap"

inside web.config

    <siteMap defaultProvider="DefaultSiteMap" enabled="true">
<providers>
<add name="DefaultSiteMap" type="System.Web.XmlSiteMapProvider" siteMapFile="~\SiteMaps
\Default.sitemap" />
</providers>