MVC and Web API Projects in the same Solution

后端 未结 2 1804
忘了有多久
忘了有多久 2021-02-04 17:58

I created a solution a while ago that contains a Web API 2 project (provides JSON data to mobile devices) and a Class Library (includes my data access services).

The Web

2条回答
  •  攒了一身酷
    2021-02-04 18:32

    This 2 projects are independent from each other like 2 different applications even if they are in the same solution.

    To succeed what you try to achieve you have to:

    1) Deploy your MVC project to www.example.com (main virtual application).

    2) Deploy your WebAPI project to www.example.com/api (api folder is a virtual application). Don't forget to remove api from your WebAPI routes (other wise you have to use this route www.example.com/api/api/controller).

    Doing this you can acces independently both projects in the same url.

    For NInject part, you can register again the services in the MVC project. Another solution will (which i recommend) be to make a class library project and register there the services after that you reference this class library in both projects.

提交回复
热议问题