I am trying to use the ASP.NET MVC Codeplex Sitemap project with Custom Dynamic Node provider. This is my node provider code. It uses some repository to access the DB. I actually don't use DI in this class but the application inherits NinjectHttpApplication and the Sitemap has problems acquiring controller.
public class ContentPageDynamicNodeProvider : DynamicNodeProviderBase
{
private IRepository _repository;
public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
{
// Build value
var returnValue = new List<DynamicNode>();
// Create a node for each content page
_repository = new XmlDefaultRepository(ContentType.Page);
foreach(var page in _repository.GetInstances())
{
DynamicNode node = new DynamicNode();
node.Title = page.Title;
node.ParentKey = "Default";
node.RouteValues.Add("slug", page.Slug);
returnValue.Add(node);
}
// Return
return returnValue;
}
}
Then in Site.Master I try to render the breadcrumbs like this:
<%=Html.MvcSiteMap().SiteMapPath() %>
My default route that starts when running the site is Page/Display/{slug} and for slug I use the "Default", here is the global.asax.cs part
routes.MapRoute(
"DefaultPage", RouteType.Regular,
"",
new { controller = "Page", action = "Display", slug = "Default" }, null
);
routes.MapRoute(
"PageBySlug", RouteType.Regular,
"{slug}",
new { controller = "Page", action = "Display", slug = "Default" }, null
);
routes.MapRoute(
"Default", RouteType.Regular,
"{controller}/{action}/{slug}",
new { controller = "Page", action = "Display", slug = "Default" }, null
);
The problem I have is that when Custom Site Node Provider is in place I get this error at runtime:
Value cannot be null or empty. Parameter name: controllerName
This is the stack trace (maybe it will help someone identify what is going on). As far as I can tell it goes to Ninject for controller but does not get one.
[ArgumentException: Value cannot be null or empty. Parameter name: controllerName]
System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +167 Ninject.Web.Mvc.NinjectControllerFactory.CreateController(RequestContext requestContext, String controllerName) +151 MvcSiteMapProvider.AuthorizeAttributeAclModule.IsAccessibleToUser(IControllerTypeResolver controllerTypeResolver, DefaultSiteMapProvider provider, HttpContext context, SiteMapNode node) +533 MvcSiteMapProvider.DefaultAclModule.IsAccessibleToUser(IControllerTypeResolver controllerTypeResolver, DefaultSiteMapProvider provider, HttpContext context, SiteMapNode node) +149 MvcSiteMapProvider.DefaultSiteMapProvider.IsAccessibleToUser(HttpContext context, SiteMapNode node) +24
System.Web.SiteMapNode.IsAccessibleToUser(HttpContext context) +17
System.Web.SiteMapProvider.ReturnNodeIfAccessible(SiteMapNode node) +42
System.Web.StaticSiteMapProvider.FindSiteMapNode(String rawUrl) +176
MvcSiteMapProvider.DefaultSiteMapProvider.FindSiteMapNode(HttpContext context) +282
System.Web.SiteMapProvider.get_CurrentNode() +56 MvcSiteMapProvider.Web.Html.SiteMapPathHelper.SiteMapPath(MvcSiteMapHtmlHelper helper, String separator, String separatorCssClass, String linkCssClass, Boolean currentNodeAsLink, Object htmlAttributes) +81
MvcSiteMapProvider.Web.Html.SiteMapPathHelper.SiteMapPath(MvcSiteMapHtmlHelper helper) +30
ASP.views_site_master._Render_control1(HtmlTextWriter __w, Control parameterContainer) +499
Any help appreciated.
Also please note that without the custom node provider (just the static nodes in .sitemap file) everything works fine.