llCorvinuSll llCorvinuSll - 1 year ago 121
C# Question

Attribute Routing for ApiControllers from external assembly

I have a large ASP.NET MVC 5 application, and now I want to implement Web API for it. But I want to put ApiControllers in a separate project.

I have problem with organizing routes for the Web API:

I want my main application Routes by


And the API maps on


And for the API, I want to use Attribute Routing, but can't setup WebApiConfig with proper way.

How to organize this, retaining the ability to use "Attribute Routing"?

Answer Source

I found the solution:

For ApiControllers it is not necessary to reimplement Factories.

In project Web (main), we need:

  1. Add dependency to project with ApiControllers

  2. Edit Global.asax this way




  3. in WebApiConfig.Register


    to enable Attribute Routing.

Now the Web API engine can find all ApiControllers in the Scope.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download