views:

435

answers:

5

If I want my url to look like, www.mysite.com/sitemap.xml, how would my route look in my Global.asax file?

What is the simplest way for me to route and return that static Sitemap.xml file?

+1  A: 

You shouldn't need a route for this type of file. Simply put the .xml file in the root of your application directory, and the webserver should be able to serve it up with the URL that you specified.

ASP.Net MVC ignores static file types out of the box.

womp
A: 

Is your sitemap.xml in the root of your site? If so, you don't need to specify a route. The sitemap.xml will be the file served by default.

Kurt Schindler
+1  A: 

I believe that, like any static files in your site (images, scripts, css), it should just work. See Phil Haack's blog on this.

The only time you would need a route for it is when you want it to be generated dynamically; when you don't have a static file on disk but want to generate one on the fly. In this case you'd map it to the controller and action that will handle the content generation.

tvanfosson
A: 

ASP.Net MVC does not stop you from serving out your files by filepath at all. In fact it's perfectly fine to serve all the content you want (Even aspx pages) by path as long as they're not overridden by a route.

So your Sitemap file is just fine and you needn't write a route for it. Just write the path like this:

http://myserver.com/sitemap.xml

I guess you're going to send it to Google Webmasters, or wherever.

Cyril Gupta
A: 

What if there is a single static file that you want served from two places. A route which presents a second location as valid but serves the first and actual location would be good. How could you do this?

nabbed