Asp.NET Web Api - multiple apis/namespaces

无人久伴 提交于 2019-12-11 03:21:44

问题


In my MVC4 web app, I need to support multiple APIs. I looked around and apparently in Web API, Controllers with same name in different name spaces is not supported.

What are my options?

Ex: I want to be able to provide to my API consumers links like,

http://domainurl/api/api1/Students...
http://domainurl/api/api2/Students...

A Student Resource in api1 can be totally different from the one in api2. In such cases what is the best approach? I do not want to make it a single api and handle it through url parameters.


回答1:


Maybe it might be better to seperate the 2 different APIs in to two different projects and have them worry about their own Apis.

  • MyApi.V1.csproj
  • MyApi.V2.csproj

Then have IIS point to the seperate versions using a virtual application

  • http://myapi.com/v1/values
  • http://myapi.com/v2/values

I think this is more manageable than smashing them into the same project file. Plus this will help each project out with reflection if you decide to use any resolvers.



来源:https://stackoverflow.com/questions/13298081/asp-net-web-api-multiple-apis-namespaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!