Ripin
Ripin

Reputation: 35

WebApi Map Router

I am using WebApi in our project. We have same controller name defined under different sub-folder. Like:

Controllers
    |----Admin
    |      |----MyProjectsController.cs
    |
    |----User
          |----MyProjectsController.cs

How can we define a route config for such scenario.

/api/admin/MyProjects
/api/user/MyProjects

Thanks.

Upvotes: 0

Views: 44

Answers (1)

JotaBe
JotaBe

Reputation: 39014

This is not directly supported by route templates because the namespace is not considered when using Web API controllers. You need to use Web API routing attributes. And you have to manually specify them (they now nothing about the folder or namespace in which the Controller is included).

Particularly you should have a look at Route prefixes. For example:

[RoutePrefix("Admin")]
public class MyProjectController: ApiController

Upvotes: 2

Related Questions