简体   繁体   中英

What is the correct way to define the Path of WebAPI in a IIS Server

I have a project with two subprojects. first subproject is the SPA with angularjs and the second subproject is my WebAPI 2. To get the entire project on a production environment (IIS Server) I deployed the first project with depending to the second project (WebAPI) on the IIS.

The SPA starts correctly. But the WebAPI always sends no data. The request path is: http://localhost:52131/api/persons

But I think localhost is wrong, because the IIS isn't on my local computer. I access on the server with remote access.

The SPA works on the address: kinga-m/myfirstspa

Do I have to deploy the WebAPI separatly on the server or is it enough to set in the project settings that webapi is a dependency?

Currently I've defined in the settings of WebAPI on tab Web -> IIS Express with the project url " http://localhost:52131/ " but I think that's wrong.

@Yuro, Basically deploying WebAPI on IIS is not a rocket science. You can have both SPA application & WebAPI application on same IIS server or different, it doesn't matter.

WEB API: Make sure you have created proper 'Application' under Default web site and point web API folder, Along with proper application pool assigned - for correct .NET version. Once this is done, you can test your API directly using fiddler URL something like:

http://localhost/[applicationName]/api/Persons

SPA: You can create another application under default web site and point to SPA web site. Also make sure, you are configuring same URLs into your SPA calls to WEB API. So if above mentioned URL works for you separately, then it will definitely work thru SPA.

Suggestion: always test API calls separately.

Hope you have enabled CORS into your web api, too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM