简体   繁体   English

在IIS服务器中定义WebAPI路径的正确方法是什么

[英]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. 第一个子项目是带有angularjs的SPA,第二个子项目是我的WebAPI2。为了在生产环境(IIS Server)上获得整个项目,我根据IIS上的第二个项目(WebAPI)部署了第一个项目。

The SPA starts correctly. SPA正确启动。 But the WebAPI always sends no data. 但是,WebAPI始终不发送任何数据。 The request path is: http://localhost:52131/api/persons 请求路径为: http:// localhost:52131 / api / persons

But I think localhost is wrong, because the IIS isn't on my local computer. 但是我认为localhost是错误的,因为IIS不在我的本地计算机上。 I access on the server with remote access. 我通过远程访问在服务器上进行访问。

The SPA works on the address: kinga-m/myfirstspa SPA在以下地址工作: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? 我是否必须在服务器上分别部署WebAPI,或者是否足以在项目设置中设置webapi是依赖项?

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. 目前,我已经在选项卡Web-> IIS Express的WebAPI设置中使用项目URL“ http:// localhost:52131 / ”定义了,但是我认为这是错误的。

@Yuro, Basically deploying WebAPI on IIS is not a rocket science. @Yuro,基本上,在IIS上部署WebAPI并不是一门科学。 You can have both SPA application & WebAPI application on same IIS server or different, it doesn't matter. 您可以将SPA应用程序和WebAPI应用程序都放在同一IIS服务器上,也可以在不同的IIS服务器上,这没关系。

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. WEB API:确保已在“默认”网站和指向Web API文件夹下创建了正确的“应用程序”,并分配了正确的应用程序池-用于正确的.NET版本。 Once this is done, you can test your API directly using fiddler URL something like: 完成此操作后,您可以使用提琴手URL直接测试您的API,例如:

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

SPA: You can create another application under default web site and point to SPA web site. SPA:您可以在默认网站下创建另一个应用程序,然后指向SPA网站。 Also make sure, you are configuring same URLs into your SPA calls to WEB API. 还要确保,您在对WEB API的SPA调用中配置了相同的URL。 So if above mentioned URL works for you separately, then it will definitely work thru SPA. 因此,如果上述URL单独为您工作,那么它肯定会通过SPA工作。

Suggestion: always test API calls separately. 建议:始终单独测试API调用。

Hope you have enabled CORS into your web api, too. 希望您也已将CORS启用到Web api中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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