2 Answers
2

To accomplish your goal, you would need three separate routes in RegisterRoutes in global.asax.cs, which should be added in the following order, and must be before the Default route (this assumes that id must be an integer):

so there is no generic way of setting it so that I don't have to hard code the action or controller name?
–
MicahNov 4 '11 at 17:11

Given the requirements you outlined, the routing must be very specific. However, if you have a consistent URL naming scheme, and consistent action names between your controllers, it would be possible to make rules to serve multiple controllers, not just your Users controller.
–
counsellorbenNov 4 '11 at 17:16

@Micah - yes there are, but not for the mapping from URL to Action that you stated in your question. I added this to my answer as there is more room.
–
iandotkellyNov 4 '11 at 17:17

counsellorben got to the answer before I did. If you want those exact URLs and those exact methods then that is the only way. You could reduce the number of routes by combining GetUser and GetAllUsers into one action with a nullable id, e.g.

But this would require you to change the URLs you wanted so /users/getuser/1234 would go to GetUser(int id) and /users/getallusers would go to GetAllUsers(). This is untested by the way - might be some slight mistakes.