Mixing Web Api and ASP.Net MVC Pages in One Project

前端 未结 3 724
春和景丽
春和景丽 2020-11-28 10:20

How do I mix Web API and ASP.Net MVC pages in one project?

For instance, I have model User. I would like, within the same project, to have an ApiController that wou

3条回答
  •  难免孤独
    2020-11-28 11:06

    The WebApi implementation should be added as a separate Area in the MVC application. It is a natural fit. Doing this gives you the separate namespace that Mike Wasson recommended, plus it gives you a natural way to set up the /api routing. You get a separate model folder

    Additionally, it is very specifically separated from the rest of the project. If requirements in the future are ever such that you need to separate the api implementation into a separate project, having the api implementation isolated to a separate area makes that breaking it out a lot easier.

提交回复
热议问题