C# mvc3 redirect sitemap.xml to controller action?

You can use MVC's routing feature to achieve this.

Up vote 0 down vote favorite share g+ share fb share tw.

I want to redirect each call on a website made for domain.com/sitemap.xml to a controller action. How can I achieve this? I've got this till so far, but the statuscode returned is an 302.

I want to return an 200 status with it, but still redirect / rewrite to an controller action. The reason i'm asking is that I want each call for the mentioned url redirected to a controlleraction. The controller does some foo en generates an xml sitemap.

Then the output of this controlleraction needs to be returned. Protected void Application_BeginRequest() { //Check if an call for the sitemap. Xml has been made if (Request.

Path == "/sitemap. Xml") { Response. RedirectToRoute("XmlSitemap"); } } c# asp.

Net-mvc-3 url-rewriting link|improve this question edited Apr 16 '11 at 15:29 asked Apr 16 '11 at 15:21Rob1,4521920 98% accept rate.

You can use MVC's routing feature to achieve this: routes. MapRoute( "Sitemap", "sitemap. Xml", new { controller = "Home", action = "Sitemap" } ); With this placed placed in your global.

Asax file, all requests to domain.com/sitemap.xml will be routed to the Home controller's Sitemap action.

Stupid me, the routing can already catch the url and redirect it to the right controller. Was creating unnecessary difficulties for my own this way. Thanks!

– Rob Apr 16 '11 at 15:46 Happens to everyone in one form or another. :) – Christopher Harris Apr 16 '11 at 15:47.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions