views:

141

answers:

1

Relevant route registration code:

routes.MapRoute(
  "QuestionsMostRecent",  
  "questions", 
  new { controller = "questions", action = "most_recent" }
);
routes.MapRoute(
  "ControllerActionFormat", 
  "{controller}/{action}.{format}"
);

Route generation code:

Url.RouteUrl(new {
  controller = "questions", 
  action = "most_recent", 
  format = "rss" 
});

I expect to receive "/questions/most_recent.rss", but instead I receive "/questions?format=rss". I realize I can force my expected result by referencing the route name "ControllerActionFormat", but I am curious about why exactly the routing system is matching the first route. Can anyone shed some light on this?

+1  A: 

Because both of them match, but you have the more broadly defined route registered first. Register the more specific route first and it will solve the issue.

womp