I am using MVC3, C#, Razor, mvcSiteMapProvider V4.
I am using "Mvc.sitemap"
<mvcSiteMapNode title="Reports" controller="Report" action="Index" preservedRouteParameters="ClientId" route="Report">
<mvcSiteMapNode key="Report_Section" title="Sections" controller="Section" action="FilterByReport" preservedRouteParameters="ClientId,ReportId" route="Report_Section">
<mvcSiteMapNode key="Background" title="Background" controller="Wizard" action="Index" preservedRouteParameters="ClientId,ReportID,SectionID,SectionName" route="Background"/>
The "Global.asax" custom routes look like:
routes.MapRoute("Report", "Report/{ClientId}", new { controller = "Report", action = "Index", ClientId = UrlParameter.Optional });
routes.MapRoute("Report_Section", "Report/{ClientId}/Section/{ReportId}", new { controller = "Section", action = "FilterByReport", ReportId = UrlParameter.Optional });
routes.MapRoute("Background", "Report/{ReportID}/SectionID/{SectionID}/SectionName/{SectionName}", new { controller = "Wizard", action = "Index", ReportID = UrlParameter.Optional, SectionID = UrlParameter.Optional, SectionName = UrlParameter.Optional });
The "Report" and "Report_Section" routes work fine. However when I go into the "Background" route I lose all of my route structure, for the "Report_Section" and "Report" routes, in the mvcSiteMap BreadCrumb URL. Instead I get a GUID ie:
http://localhost/7ebe9bb9-a663-43fd-9fb1-865866be12b9
I believe this might be the XML Node Key that is autogenerated. However it prodocues a 404 when clicked.
I should get something like:
Reports
http://localhost/Report/10
Sections
http://localhost/Report/10/Section/100
Any ideas what could be causing this?
Thanks.
You will get a Guid for the URL if the URL resolver cannot find a match. Throwing an exception in this case was causing other issues (see why does URL resolver throw an exception).
However, I can't tell you exactly why it is not matching without seeing more of your configuration. A clue is that we are using UrlHelper.RouteUrl(string, RouteValueDictionary) to resolve the URL. You can try calling it explicitly with your route values and route name. Also, see the source code for other clues.
One thing I noticed that looks off is that you are preserving the ClientID route parameter for Background when it is not even used in that route. Keep in mind that preserving route parameters only copies them from the current HTTP request and your other nodes will appear to forget them.
PreserveRouteParameters is typically used for CRUD operations where you make data editing pages. If you want it to appear to "remember" the user's navigation path, then you need to add 1 node per unique route value combination to your sitemap.
If the above doesn't help, please create a small demo project that exhibits the problem and either upload it to GitHub or else zip it and make it available for download, then open a new issue at GitHub with the link to the demo.