asp.net-mvcmaproute

Customize ASP.NET MVC MapRoute


Default ASP.NET MVC project has one MapRoute like

routes.MapRoute(
            "Default",
            "{controller}/",
            new { controller = "Home", action = "Index" }
            );

And urls like these are equivalent: www.mysite.com, www.mysite.com/home, www.mysite.com/home/index

But if I trying to use a MapRoute like

            routes.MapRoute(
            "Sitemap",
            "{controller}/{action}",
            new { controller = "Sitemap", action = "ShortMap" }
        );

and test url www.mysite.com/sitemap I recieve error 404 but I'm expecting that it's work like www.mysite.com/sitemap/shortmap

How to write this MapRoute correctly?


Solution

  • Best thing I have found to aid in map route issues is Phil Haack's route tool http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx. It's a great way to see which and how your routes are being used.

    What happens when you try /sitemap/action