MVC 3 How to use MapRoute

Anton Gildebrand picture Anton Gildebrand · Jun 22, 2011 · Viewed 27.3k times · Source

Could someone show me how to use the MapRoute method? I have tried creating my own routes, but it's not working. What i want to accomplish is a route that routes "http://servername/home/default.aspx" into controller "Home" and action "Default". Also, would it be possible to say that if the user is browsing the default.aspx "file", it would actually point to the "Index" action?

I have tried reading the MSDN references and googling, but it didn't make me any wiser.

Answer

Darren Hughes picture Darren Hughes · Sep 21, 2011

Probably too late to help the developer who raised the question but may help someone else. New to MVC but what I found is the map routes seem to be processed in the order they are added. I had a similar problem, my specific route was not working until I started adding the default route as the last route.

If the default map route is added before your custom one and your custom URL matches the structure defined by the default map route you will never reach your custom route.