views:

84

answers:

2

In a visual studio 2008 project, how can one structure his controllers to accessible in the following directive?

http://localhost/MyWebsite/api/users/get/1

Both /api/ and /users/ are controllers "get" being a method of "users" with 1 as the parameter

Essentially I am talking about achieving REST i would assume.

Any ideas?

Thanks, Nick

Fixed

Phil Haack has developed an extension called Areas which allows one to group his controllers in an ASP.Net MVC project. Grouping Controllers

+1  A: 

You will need to setup your own custom route. See this tutorial for more details. Combine this with the AcceptVerbs attribute to achieve REST functionality.

Kyle Trauberman
+1  A: 

If you're going for REST api should not be a controller, api is a method of accessing your user. the other being html.

Your route should be localhost/user/1 - personally I'd leave the get out. It's not descriptive, you can get a list of users or a single user. If you want something use Detail. Then in your controller you respond to the request appropriately depending on who your caller is (api vs html).

ktrauberman is right though, when it's time to start nesting your routes you'll have to use a custom route in your global.asax. An example of this would be:

localhost/user/{userId}/address/{addressId}

Kyle

Kyle West