且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在一个项目中混合 Web Api 和 ASP.Net MVC 页面

更新时间:2023-08-24 17:45:40

您可以将它们放在单独的命名空间中,例如 MyApp.Controllers.UsersController 和 MyApp.Controllers.WebAPI.UsersController.

You can put them in separate namespaces, e.g MyApp.Controllers.UsersController and MyApp.Controllers.WebAPI.UsersController.

这将允许您在 MVC 和 WebAPI 中公开类似的 URI 路由,例如:

This would let you expose similar URI routes in MVC and WebAPI, eg:

/users/1      << MVC view
/api/users/1  << Web API