This project is read-only.

Exporting the sitemap for search engine indexing

When building a website, chances are that you want to provide an XML sitemap used for search engine indexing.

Option 1: Using the XmlSiteMapController class

If you just require a sitemap.xml file to be available, consider adding teh following line of code in the Application_Start event:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using MvcSiteMapProvider.Web;

namespace MvcMusicStore
    public class MvcApplication : System.Web.HttpApplication
        public static void RegisterRoutes(RouteCollection routes)
            // ... your routes registration here

        protected void Application_Start()

            XmlSiteMapController.RegisterRoutes(RouteTable.Routes); // <-- register sitemap.xml, add this line of code


This will make sitemap.xml available in the easiest way.

Large sitemaps

Whenever a sitemap exceeds 50.000 nodes, the XmlSiteMapController will automatically split your sitemap into a sitemap index file (sitemap.xml) which references sub-sitemaps (sitemap-1.xml, sitemap-2.xml etc.) as described on

Option 2: Using the XmlSiteMapResult class

The XmlSiteMapResult class creates an XML sitemap that can be submitted to Google, Yahoo and other search engines to help them crawl your website better. The usage is very straightforward:

public class HomeController
    public ActionResult SiteMapXml() 
        return new XmlSiteMapResult(); 

Optionally, a starting node can also be specified in the constructor of theXmlSiteMapResult .

GZip compression of sitemap files

Whenever a client sends an HTTP request header with Accept-encoding set to a value of gzip or deflate, the XmlSiteMapResult class (which is also used internally in the XmlSiteMapController) will automatically compress the sitemap using GZip compression.

Last edited Oct 27, 2010 at 8:19 AM by maartenba, version 3


cardiac7 Jul 20, 2012 at 5:06 PM 
Hi Maartenba, thanks for the great provider. I am not able to create a sitemap.xml file either, using option #1. No errors/message are given on compile, any suggestions on where to begin to debug this?

maartenba Mar 25, 2011 at 11:02 PM 
For option one, can you register a route for it? Or tell Ninject to resulve this controller?

ieming Feb 24, 2011 at 8:33 AM 
I tried to use option 2, but when i type, it gives me back with a 404.
Tried option 1, but I am getting "No parameterless constructor defined for this object." due to the use Ninject for dependency injection.

Can someone please show me the light?