Jonathan Wood
Jonathan Wood

Reputation: 67193

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.

Upvotes: 4

Views: 4661

Answers (2)

Vaclav Elias
Vaclav Elias

Reputation: 4151

For Webforms, you can also update your web.config as mentioned above, you just use plain aspx or ascx page and then do magic with rewrite :-) (I use .net 4.0)

e.g.

<system.webServer>
<rewrite>
  <rules>
    <rule name="Main Sitemap" stopProcessing="true">
      <match url="^sitemap.xml"/>
      <action type="Rewrite" url="sitemap/sitemap.aspx" appendQueryString="false"/>
    </rule>
  </rules>
</rewrite>
</system.webServer>

Upvotes: 2

Charandeep Singh
Charandeep Singh

Reputation: 972

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

For MVC, use routing:

routes.MapRoute("Sitemap", 
                "sitemap.xml",
                new { controller = "Home", action = "Sitemap" })

Upvotes: 9

Related Questions