Question

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!

Was it helpful?

Solution

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:

Project for the native JS/HTML - Has nothing to do with .NET!

And the second project (WEB-API project):
enter image description here

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

OTHER TIPS

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");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top