Hello there, I was wondering if anyone has done this yet or has any examples on how to create a Google Sitemap for an MVC website.

Any help or example would be appreciated.

Im talking about this:

+2  A: 

The easiest way would be to use any one of a number of free sitemap builders out there - they will crawl your site, follow links, and generate a sitemap XML file for you.

Here's one for example

Eric Petroelje

Here's a post that might give you some ideas. Basically it generates a sitemap from route values.

Darin Dimitrov
+1  A: 

I used Mike Brind's Sitemap code, with a small change.

You need to add the XNamespace to every XElement, otherwise Google spits the dummy.

Here's my version:

public ContentResult Index()
            XNamespace ns = "";
            const string url = "{0}";
            var items = _db.DataAccessHere();
            var sitemap = new XDocument(
                new XDeclaration("1.0", "utf-8", "yes"),
                new XElement(ns + "urlset",
                    from i in items
                    //Add ns to every element.
                    new XElement(ns + "url", 
                      new XElement(ns + "loc", string.Format(url, i.ItemID)),
                          new XElement(ns + "lastmod", String.Format("{0:yyyy-MM-dd}", i.DateAddedUTC)),
                      new XElement(ns + "changefreq", "monthly"),
                      new XElement(ns + "priority", "0.5")
            return Content(sitemap.ToString(), "text/xml");

Credit to Mike for posting the original article and code.


If you site has more than 50000 url then you may want to use Online Sitemap Generator. It is free and work well with small as wel


so here's the thing, using generators will just about create a link for "everything" in your site. So if you have, let's say a card site, and you have like a hundred thousand card items, each with it's own link and all, you'll likely see the same amount of links. If you want that, then xml sitemap generators are the way to go.

But if you want it a little bit personalized, you can do these:

List all major sections of your sites. This is easy to do considering that most MVCs are using the "clean URLs" sort of thing. kinda like ""

Create an XML document, depending on the language you're using.

At the minimum, you should have a document like this:

<?xml version="1.0" encoding="utf-8"?> 
    <urlset xmlns=""&gt; 
      <!-- more here -->

For more advanced structure, check this: