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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.