Setting app a separate Web API project and ASP.NET app

泄露秘密 提交于 2019-11-29 15:38:29

问题


I am trying to consume a Web API service from another ASP.NET classic project (actually it is a native JS and Html Web application). How can I configure these these two separated projects to talk with each other, on VS2012?

The final result would be:

http://localhost:8080/api/products

will return a list of products (JSON) by routing to ProductsController located on the WebAPI project,
And

http://localhost:8080/index.html

will be routed to this page on the Second project - The native HTML/JS project.

How can I configure the logical to physical Directories in these two project? Thanks!


回答1:


As it turned out it's pretty simple. All I had to do is configure these both projects to share the same port on the local IIS: So for the native JS/HTML (my second project) I use:

And the second project (WEB-API project):

That is it! Now the js can consume the Web-Api!




回答2:


You just need a single project: ASP.NET Web API. I would put the index.html in the root and javascript files under scripts or js folder.

Normally static content such as js and html can be served directly by IIS in your ASP.NET Web API project. You need to make sure you add them to ignore rules in the startup:

RouteTable.Routes.IgnoreRoute("*.js");
RouteTable.Routes.IgnoreRoute("*.html");


来源:https://stackoverflow.com/questions/18429660/setting-app-a-separate-web-api-project-and-asp-net-app

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