Problems with dynamic nodes & helpers returning incorrect node names/breadcrumbs

Jul 4, 2010 at 1:40 PM
Edited Jul 6, 2010 at 12:00 PM

I'm building an online store, and have some dynamic node providers working. When I view the sitemap itself using Html.MvcSiteMap().SiteMap("siteMap"), the sitemap displays perfectly, with the home page, products browse page, master categories, nested subcategories, and all the products underneath.

My sitemap file is as follows:


<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="" enableLocalization="true">
    <mvcSiteMapNode title="Home" 
        <mvcSiteMapNode title="Products" controller="Categories" action="Index">
            <mvcSiteMapNode title="Master Categories" 
dynamicNodeProvider="CompanyWholesaleWebsite.Services.MasterCategoryDynamicNodeProvider, CompanyWholesaleWebsite"> <mvcSiteMapNode title="Browse" action="Details"
dynamicNodeProvider="CompanyWholesaleWebsite.Services.CategoriesDynamicNodeProvider, CompanyWholesaleWebsite"> <mvcSiteMapNode title="Details" controller="Products" action="Details"
dynamicNodeProvider="CompanyWholesaleWebsite.Services.ProductsDynamicNodeProvider, CompanyWholesaleWebsite" /> </mvcSiteMapNode> </mvcSiteMapNode> </mvcSiteMapNode> <mvcSiteMapNode title="Sitemap" controller="Home" action="Sitemap" /> <mvcSiteMapNode title="About Us" controller="Home" action="About" /> </mvcSiteMapNode> </mvcSiteMap>


The MasterCategoriesNodeProvider gets categories that have parentId == null, and sets their "key" to Category_{id}.

The CategoriesDynamicNodeProvider returns categories that have parentId != null, sets their "key" to Category_{id}, and node.ParentKey to Category_{parent_id}.

The ProductsDynamicNodeProvider returns products nested in the correct category as per above.

For routes, I'm using the following:


                new { controller = "Categories", action = "Details", permalink = UrlParameter.Optional }
                new { controller = "Products", action = "Details", permalink = UrlParameter.Optional}

                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults


As mentioned earlier, the sitemap itself appears perfectly when displayed, with all nodes displaying with the correct nesting. The routevalues are coming through properly; all of the hyperlinks in the sitemap correspond to the respective nodes, and follow the routing convention I've defined in global.asax

The problem I'm having, is that when I view an actual product, I always (incorrectly) get the breadcrumb (using Html.MvcSiteMap().SiteMapPath()) for the first category, and the first product within that category - no matter which product I view. Html.MvcSiteMap().SiteMapTitle() also always returns the incorrect node title as per the breadcrumb.

I've verified that the node providers are returning nodes with correct parentnode IDs, keys, etc. It just doesn't seem to want to work - and I'm at my wit's end with this issue. The node titles and breadcrumb helper functions are being called from within the masterpages for the respective pages.

Any ideas anyone?

Jul 6, 2010 at 11:57 AM
Edited Jul 6, 2010 at 11:59 AM

I still haven't had much progress on this, but it seems to be an issue with the way MvcSitemap is matching "MvcNode" to the route values. I've spent time stepping through and trying to debug the process, but haven't had much luck yet (I'm not a developer by trade).

I've verified that all of the nodes being added correctly (by dumping out the contents of Sitemap.RootNode.ChildNodes). All of the nodes have the correct URL and route values set. I also tried simplifying the routes, and several other things - but nothing has helped so far.

One weird thing that happened whilst stepping though DefaultSiteMapProvider.FindControllerActionNode() was that all of a sudden it started working properly. I thought it may have been some sort of caching issue, possibly related to running the site under Cassini. I tried it once published to my local IIS 7.5 instance, and the problem reappeared. I had to take screenshots to prove that it worked - and work it did.

I'm really looking forward to getting this issue sorted out, as this functionality is vital for the site - and I wouldn't want to start creating it from scratch.

Jul 6, 2010 at 3:46 PM
Edited Jul 6, 2010 at 3:59 PM

Can anyone here tell me how to disable caching? The problem I've described disappears after the cache duration expires (or I set my PC's clock ahead by >5 mins)

I've tried setting the cacheDuration attribute to "0" on the MvcSiteMapProvider, but that just results in the page not loading at all.

Jul 20, 2010 at 7:32 AM

Have you tried using the latest source code? (Source code tab above, download the latest code base and check for the 2.1.0 branch...)

Jul 20, 2010 at 7:42 AM
Hi Maarten. Thanks for getting back to me. Yes, I've tried that before - and just re-downloaded and built the 2.1 branch just now. Same problem. Until the cache expires (which I've set to 1 min), the breadcrumbs are returning the complete incorrect path. As soon as the cache has expired, it works beautifully. Cheers, Daniel
Jul 20, 2010 at 7:57 AM

Would it be possible to send me your code base and exact steps to reproduce this?

Jul 20, 2010 at 8:05 AM
Sure. I can give you access to my SVN repo. There are no steps as such, just open up the project and press F5. Is that ok with you?