I want to create a dynamic (fetching data from the database) XML sitemap which I can submit to Google webmaster tools.

Surprisingly, I couldn't find any recent controls/code online to do this. The most recent code I found was this which is for ASP.Net 2.0. I don't mind using this, but I suspect it's outdated.

Can somebody please point me in the direction of code which accomplishes this?

Thanks, WT


A couple of options include:

The ASP.Net SiteMap infrastructure. It allows you to write a custom sitemap provider like this one, which uses Micosoft Access, to generate a sitemap.

You can also find a very simple sitemap generator project on this site.

Another option (and fun learning experience) is to write your own by just looking at the sitemap protocol, and using Linq To SQL along with Linq To Xml to generate the format. Here is an example uses Linq To SQL and Linq To XML to generate XML.

Finally, Google also accepts RSS/Atom feeds, so you could generate one of those instead. If you go this route then you can make use of the SyndicationFeed class. There are also a couple open source options available.


Actually i just done it recently using LinqToXMl

Actually the string that is returned by that code is written directly to the Response object. I use a .ashx HttpHandler to deliver the content as XML and using Routing to serve it under the name of sitemap.xml. Also you should put it on your robots.txt file

Carlos Muñoz

I just hit an aspx page, which generates the sitemap.xml file and also submits it to Google, Yahoo!, Bing, and Ask.

Here is a more extensive example of the details.

How-to Generate and Submit Your Sitemap to Google, Yahoo!, Bing, and Ask