Specify route data in sitemap file

May 6, 2011 at 5:25 AM

I have static pages and all pages uses the same controller and action which is Home and Index. It diffrentiate by the "page" route parameter. This is my route:

routes.MapRoute("HomeViews", "Home/{page}/{subpage}", new { controller = "Home", action = "Index", subpage = UrlParameter.Optional });

And this is the action:

        public ActionResult Index(string page, string subpage)
            if (!string.IsNullOrEmpty(page))
                return View(page);

So when ever I want to add new static page, no action needed but just I need to create a View file.


Then How to create the sitemap file since it take the controller and action to generate URL. How can I specify the route data page=About for About view, page=Contact for Contact view etc?


    <mvcSiteMapNode title="Home" controller="Home" action="Index" description="Home" />
    <mvcSiteMapNode title="About" controller="Home" action="Index" description="About Us"  ??? />
    <mvcSiteMapNode title="Contact" controller="Home" action="Index" description="Contact Us" ??? />

May 6, 2011 at 1:11 PM

I think I'm having the same problem:


Didn't get a reply yet ):

May 6, 2011 at 1:11 PM
Edited May 6, 2011 at 1:11 PM


May 26, 2011 at 2:18 PM

Simple :-)

<mvcSiteMapNode title="About" controller="Home" action="Index" description="About Us" page="About" subpage="Us" />

Jun 1, 2011 at 10:42 AM

Not that simple dude. Have you try my code?

It will become http://domain.com/?page=About&subpage=Us. It fallback to query string . I tried before.

What I remember, the extra unrecongnized attribute in the sitemap become query string is come from native ASP.NET sitemap provider.

The question asking to set Route Data in the sitemap node!


Wait a min...i tryed again but different way, seems only and only this combination to work:

routes.MapRoute("HomeViews", "Home/{action}/{subaction}", new { controller = "Home", subaction = UrlParameter.Optional });

<mvcSiteMapNode title="About" controller="Home" action="About" description="About Us" subaction="Background" />


The other way like using same controller and same action but differentiate by the custom route data will become query string.

I believe many static pages is handy to create using 1 controller 1 action with multiple view but require code just like I posted in the question.