Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically Generating sitemap.xml

I've implemented a sitemap that is dynamically generated on the fly using the technique described here.

Since my site is a WebForms app, my sitemap URL ends up being www.mydomain.com/Sitemap.aspx.

This is working well, and I can use search engine webmaster tools to tell them the URL to my sitemap. However, smaller search engines may not know where to find this file. It would be better if my dynamically generated sitemap could be at www.mydomain.com/sitemap.xml. This is the standard URL for a sitemap.

What is the easiest way to generate the same sitemap data I do now but have it appear as the file sitemap.xml. Can I do it using routing, or do I need a custom HTTP handler?

I'm using webforms but also have sites using ASP.NET MVC so I'm very interested in finding the best technique to do this in both platforms.

like image 265
Jonathan Wood Avatar asked Dec 20 '22 22:12

Jonathan Wood


1 Answers

For Webforms, you can use HttpModule, check out UrlRewriting.NET

For MVC, use routing:

routes.MapRoute("Sitemap", 
                "sitemap.xml",
                new { controller = "Home", action = "Sitemap" })
like image 104
Charandeep Singh Avatar answered Jan 12 '23 20:01

Charandeep Singh