How do you dynamically build a node to replace the root?

May 13, 2010 at 12:45 AM

I want to build my site map using the attributes, but I'm running into a weird issue that makes me think I'm missing something.

It appears that I have to specify a siteMapFile for the site map provider. It also appears that the siteMapFile I specify absolutely requires at least one node in it. So I end up with a site map like this:

<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="">
    <mvcSiteMapNode title="Home" controller="Home" action="Index" />

Basically - the absolute minimum I need to specify.

However, I want to control my site map, including the root, through the attributes. I tried setting up my HomeController like this:

namespace MyApplication.Controllers
    public class HomeController : Controller
        [MvcSiteMap.Core.MvcSiteMapNode(Title = "Inferred Home")]
        public ActionResult Index()
            return View();

This yields an error where I have two site map nodes with the same URL.

I can work around it by special-casing the "Home" node, but it sort of defeats the purpose of having the attributes if I still have to have an XML site map.

Am I missing something? Some way to say "don't use the XML at all - ONLY use the attributes?"

May 25, 2010 at 3:24 PM

you can do it inside the action result metod.

using the SiteMap.CurrentNode.Title="Inferred Home";

May 25, 2010 at 3:31 PM

Modifying the site map programmatically still implies that I'm not able to mark the "root node" using an attribute - I still have to have that stub XML file, and I still have to know what the root node in that stub is, and I still have to do something different just for that one node if I want to change the title... which doesn't solve the problem I've got.

The problem I'm trying to solve is: How do I do the WHOLE MAP in attributes without any stub XML at all; OR how do I "replace" the root node in the XML with one declared in an attribute. Without putting any reference to the site map anywhere in the code except in an attribute.

(The answer may be "that's not possible right now," and that's fine, but that's the aim of the question: to determine if it's possible or not, and, if it is, how.)