KingNestor
KingNestor

Reputation: 68050

What would be an ASP.NET MVC route to a static Sitemap.xml?

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?

Upvotes: 0

Views: 2576

Answers (4)

Cyril Gupta
Cyril Gupta

Reputation: 13723

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.

Upvotes: 1

tvanfosson
tvanfosson

Reputation: 532695

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.

Upvotes: 1

Kurt S
Kurt S

Reputation: 21357

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.

Upvotes: 0

womp
womp

Reputation: 116987

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.

Upvotes: 2

Related Questions