XML sitemap with ASP.NET

This is a migrated post from my former blog at bloodsweatand.net. It was originally posted 2009-03-18.

An XML sitemap is a great way to help crawlers such as Google, MSN Search, Yahoo and ASK.com to crawl your site and also allow you to tell them how important pages on your site are relative to each other.

I created a ASP.NET handler that generates such an XML sitemap for this site, and of course you are welcome to download the source code (a Visual Studio 2008 project).

The project contains two files, a sample robots.txt which help crawlers find your sitemap and the handler, Sitemap.ashx. To implement it on your own site modify the GetSitemapPages method  in Sitemap.ashx.cs to return a list of pages in your site.

For the impatient it is also possible to tell the major search engines about your sitemap by using their webmaster tools. You can also ping Google and MSN by making HTTP requests to http://www.google.com/webmasters/tools/ping?sitemap=http://www.yoursite.com/XmlSitemap.ashx and  http://webmaster.live.com/ping.aspx?siteMap=http://www.yoursite.com/XmlSitemap.ashx. Note that you shouldn't ping them more than once per hour though, or you may anger the all mighty search engine gods.

PS. For updates about new posts, sites I find useful and the occasional rant you can follow me on Twitter. You are also most welcome to subscribe to the RSS-feed.

Comments

  1. Dave Nicoll's avatar

    Dave Nicoll 2 years ago

    Great post. Have you considered adding this to codeplex?

  2. Joel Abrahamsson's avatar

    Joel Abrahamsson 2 years ago

    Thanks Dave!

    I haven't considered adding it to Codeplex as I have regarded this as more of a stub than a complete framework for XML sitemaps. But perhaps I'll make it more complete in the future and make it into a real open source project.

  3. Baume Mercier's avatar

    Baume Mercier 2 years ago

    Hmm strange this post is totaly irrelevant to the search query I entered in google but it was listed on the first page.

  4. Joel Abrahamsson's avatar

    Joel Abrahamsson 2 years ago

    Well, this site has a XML-sitemap, maybe that helped it to get on the first page ;)

  5. sulumits retsambew's avatar

    sulumits retsambew 2 years ago

    I see you are using Blogengine.net
    Let me tell you, it is the best... I love it.

  6. proactol's avatar

    proactol 2 years ago

    nice post. thanks

  7. Dale's avatar

    Dale 2 years ago

    the zip file is corrupted

Follow me on Twitter

  1. @chraas You might want to use it for complex parts of the site and not use it for simple rendering pages. 2 days ago
  2. @chraas In theory more SOLID, but I'm not sure it's worth the price. 2 days ago
  3. @chraas Be warned that you're introducing one big chunk of complexity with EPiMVP :) 2 days ago
follow me

Latest comments

  1. Berra S wrote "Read your post at http://joelabrahamsson.com/entry/using-xfo..." on PageData objects not returned as typed when using Page Type Builder and FindPagesWithCriteria
  2. Linus wrote "1 up for behaviour being as close as expected as possible!" on A common problem with Page Type Builder and UniqueValuePerLanguage set to false
  3. Joel Abrahamsson wrote "Hi Hans, Could it be that you previously didn't have Page..." on Page Type Builder 2.0 released

About this site

This blog is built with EPiServer Community, EPiServer CMS, ASP.NET MVC and a bunch of other great products. The source code is available for download at the projects page, where you also can read more about this site and my other projects.

read more