Ad

MVC: How To Route /sitemap.xml To An ActionResult?

- 1 answer

I've got a SitemapActionResult that overrides the ActionResult, and delivers a SEO sitemap.xml when http://www.sprelle.no/Home/SiteMap is hit. So far so good.

What I would like, though, is to serve the sitemap.xml when Google visits /sitemap.xml. For that to work, I need a route that sees "sitemap.xml" and directs to /Home/Sitemap.

How do I create this mapping (in the Routes table)?

Ad

Answer

Add a map for:

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

Notice that the route, controller, and action options are hard coded.

Ad
source: stackoverflow.com
Ad