How to configure Web Api 2 to look for Controllers in a separate project? (just like I used to do in Web Api)

前端 未结 8 1790
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 17:40

I used to place my controllers into a separate Class Library project in Mvc Web Api. I used to add the following line in my web api project\'s global.asax to look for contro

8条回答
  •  伪装坚强ぢ
    2020-12-04 18:10

    I have just confirmed that this works fine. Things to check:

    References: Does your main Web API project reference the external class library?

    Routing: Have you set up any routes that might interfere with the external controllers?

    Protection Level: Are the controllers in the external library public?

    Inheritance: Do the controllers in the external library inherit from ApiController?

    Versioning: Are both your Web API project and class library using the same version of the Web API libraries?

    If it helps, I can package up my test solution and make it available to you. Also, as a point to note, you don't need to tell Web API to find the controllers with the line you added to Global.asax, the system finds the controllers automatically provided you have them referenced.

提交回复
热议问题