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 1 years ago

    Great post. Have you considered adding this to codeplex?

  2. Joel Abrahamsson's avatar

    Joel Abrahamsson 1 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 1 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 1 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 1 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 1 years ago

    nice post. thanks

  7. Dale's avatar

    Dale 9 months ago

    the zip file is corrupted

Add a comment

Allowed tags: <b>, <em>, <quote cite="">, <code>, <c-sharp-code>, <css-code>, <sql-code>, <xml-code>, <javascript-code>. If you want to display code examples, please remember to write &lt; for < and &gt; for >.

Follow me on Twitter

  1. Blogged: Learning Scala part nine – Uniform Access http://bit.ly/bmUat8 1 days ago
  2. @mikaellundin Your blog is a never ending source of wisdom. And weird mathematical problems. :) 3 days ago
  3. Bookmarked: Validate XHtml 1.0 Strict as part of your build process « Mint http://bit.ly/bOhaZj 3 days ago
follow me

Latest comments

  1. Svante wrote "Yes, I noticed that it was a singleton, and I guess the real..." on Something to beware of when using EPiAbstractions and an IoC container
  2. Joel Abrahamsson wrote "Well, first of all you wont get any arguments from me regard..." on Something to beware of when using EPiAbstractions and an IoC container
  3. Svante wrote "Hmm... Since the issue really is with the public instance co..." on Something to beware of when using EPiAbstractions and an IoC container

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