ASP.NET MVC Routing Via Method Attributes

TorgoGuy picture TorgoGuy · May 21, 2009 · Viewed 25.2k times · Source

In the StackOverflow Podcast #54, Jeff mentions they register their URL routes in the StackOverflow codebase via an attribute above the method that handles the route. Sounds like a good concept (with the caveat that Phil Haack brought up regarding route priorities).

Could someone provide some sample to make this happen?

Also, any "best practices" for using this style of routing?

Answer

DSO picture DSO · May 21, 2009

UPDATE: This has been posted on codeplex. The complete source code as well as the pre-compiled assembly are there for download. I haven't had time to post the documentation on the site yet, so this SO post will have to suffice for now.

UPDATE: I added some new attributes to handle 1) route ordering, 2) route parameter constraints, and 3) route parameter default values. The text below reflects this update.