ASP.NET MVC 2: Route order is really important

by Christoph Keller 25. January 2011 13:49
If you have multiple MVC 2 Routes, check carefully the route order! If a less specific rule comes first, it will be threated first. For an example, I have a Language-Navigation Route: routes.MapRoute( "Language_Switch", "language/{language}", new { controller = "Language", action = "Index" } ); and the default Route: routes.MapRoute( "Default", "{controller}/{action}/{id}", new {controller = "Navigation", action = "Index", id = UrlParameter.Optional} ); If the default route would come first, it would threat a specific language route as default too. This affects the method Html.ActionLink() too, because it would resolve the url according the known Routes! So just be careful! :)
DotnetKicks
DotNetShoutout

Tags: , , ,

ASP.NET | C# | MVC 2