views:

32

answers:

1

About 10 stackoverflow.com podcasts back Jeff mentioned that instead of wiring up his routes inside of the global.asax file he instead put them inside his controllers near the actions those routes would invoke.

How does one go about doing this?

Doesn't a route have to be registered before the controller it routes to is hit? Does he do it in the constructor? My mind is baffled by a chicken vs. egg issue here.

+1  A: 

Check out this question.

I highly recommend you this approach. I'm using it with great success. :)

Basic idea - we are using attribute to setup a route for specific action.
In global.asax at app start we use reflection to initialize routes.

EDIT:
More precise link here.

EDIT2:
Not related to question but might be worth checking out (in case you haven't):
RESTful URLs from MVCContrib.

Arnis L.
Very nice. I missed the attribute part while googling.
jfar
I'm glad i could help. :)
Arnis L.