Posted by Karen
on 04/01/09
I was looking for a tool/component/code to generate an xml sitemap on the fly from a SqlSitemapProvider for our new website - why invent the wheel, right? - but I didn't have much luck at first.
I found this blog post: Google Sitemaps for ASP.NET 2.0
But unfortunately you can no longer get the source code, since the author assumes that everyone is now using ASP.NET 3.5.
I also found this post, which discussed that handler and some changes to it: Generate a Google Sitemap Using ASP.NET
But that didn't have the dll or source code either.
Then I found this: Sitemaps.NET
But after setting it up, I received the "Url cannot be relative" error that other commenters were getting. Luckily James included his source code in the download. I was able to make a small change and now it works perfectly for our site.
In the WriteUrlValueElements function, I changed:
if (UrlPath.IsRelativeUrl(nodeUrl))
throw new SitemapWriterException("Url cannot be relative", siteMapNode.Key);
to:
if (UrlPath.IsRelativeUrl(nodeUrl))
nodeUrl = _siteHostUrl + "/" + nodeUrl;
That may not work for everyone, but it works just fine for me because of the way our database is set up.
I hope someone else will find this useful; here is a link to the source code and dll: sitemaps.zip