No breadcrumbs with custom MvcRouteHandler

Sep 7, 2011 at 3:44 PM

I have 2 routes in global.asax

            routes.MapRoute(
                "DefaultFriendlyUrl",
                "Page/{FriendlyUrl}",
                null,
                new string[] { "MvcApplication2.Controllers" }
            ).RouteHandler = new FriendlyUrlRouteHandler();


            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "index", id = UrlParameter.Optional },
                new string[] { "MvcApplication2.Controllers" }
            );

so, FriendlyUrlRouteHandler work all my /Page/blablabla routes and send to PageController with 1 action Index

    public class FriendlyUrlRouteHandler : MvcRouteHandler
    {
        protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            var friendlyUrl = (string)requestContext.RouteData.Values["FriendlyUrl"];

            PageItem page = null;

            if (!string.IsNullOrEmpty(friendlyUrl))
                page = PageManager.GetPageByFriendlyUrl(friendlyUrl);

            if (page == null)
            {
                requestContext.RouteData.Values["controller"] = "home";
                requestContext.RouteData.Values["action"] = "index";
                requestContext.RouteData.Values["id"] = null;
            }
            else
            {
                requestContext.RouteData.Values["controller"] = "page";
                requestContext.RouteData.Values["action"] = "index";
                requestContext.RouteData.Values["id"] = page.PageID;
            }

            return base.GetHttpHandler(requestContext);
        }
    }

Then PageController get content for my page and show it. But MvcSiteMapProvider don't show breadcrumbs for these pages

<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-3.0" enableLocalization="true">
  <mvcSiteMapNode title="Home" controller="Home" action="Index">
    <mvcSiteMapNode dynamicNodeProvider="MvcApplication2.Models.SiteMap, MvcApplication2"/>
  </mvcSiteMapNode>
</mvcSiteMap>

SiteMap.cs 

    public class SiteMap : DynamicNodeProviderBase
    {
        public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
        {
            var returnValue = new List<DynamicNode>();
            returnValue.Add(new DynamicNode() { Key = "id1", Title="CustomPage", Controller="Page", Action="Index" });
            return returnValue;
        }
    }

And my CustomPage doesn,t exists in @Html.MvcSiteMap().SiteMapPath(), but page is showed correctly. What,s wrong in my code?
So I can,t build tree of my custom pages in breadcrumbs string...