views:

151

answers:

3

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, w*ww.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?

A: 

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

Brettski
The routing debugger is also in MvcContrib http://mvccontrib.codeplex.com/
CVertex
A: 

You should probably spell the word controller correctly.

You have it spelled contoller

Jason Watts
Just mistake in question not in code.I solved the problem by this code:routes.MapRoute( "MainPage", "", new { controller="Home", action="Index" } );routes.MapRoute( "Sitemap", "Sitemap/{action}", new { controller = "Sitemap", action = "ShortMap" } );Now www.mysite.com/sitemap and www.mysite.com/sitemap/shortmap are equivalent. It was not work because of the default MapRoute influnce.
MaxFX
A: 

Make sure that the view "ShortMap" really exists. I know, it's simple - but happened to me a few times.

Dänu