【问题标题】:Web api not found after deployed in server部署到服务器后未找到 Web api
【发布时间】:2020-01-09 01:15:46
【问题描述】:

我已经在测试服务器上部署了(使用端口 9021 和站点名称 Production)Angularjs Web API 应用程序,当我点击 URL 时

http://localhost:9021/api/Item/GeAreas?P_Id=US99 

在测试服务器上,我成功获得了来自 Web API 的响应。

这是api调用的代码:

 function getAreas(P_Id) { 
        $http({
            method: 'GET',
            url: 'http://ps-test.aars/api/Item/GetAreas', 
        // url: 'http://ps-test.aars/Production/api/Item/GetAreas', // error msg: the server responded with a status of 404 (Not Found)                                             /Production/api/Item/GetAreas?P_Id=US99 
            params: { P_Id: P_Id },
            headers: { 'Content-Type': 'application/json; charset=utf-8', 'dataType': 'json' }
        }).then(function successCallback(response) {
            $scope.Areas = response.data;             
            }, function errorCallback(response) { }             
        });
    }

web.config:

 <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
 </handlers>

当我点击网址时:

http://ps-test.aars/Production/Summary.html?P_Id=US99 

在我的本地系统上,我收到一个错误:

加载资源失败:服务器响应状态为 404(未找到)/api/Item/GetAreas?P_Id=US99

不确定是什么问题。

【问题讨论】:

    标签: angularjs api asp.net-web-api http-status-code-404 asp.net-web-api-routing


    【解决方案1】:

    生产服务器上是否还有其他 web.config 文件可能会产生干扰?

    我在一个域名的子文件夹中发布了一个 Web API 2 项目,该子文件夹托管了它自己的 ASP.net 项目。该主应用程序的 web.config 被继承到 Web API 2 项目的 web.config 中,这会干扰路由。可能是因为使用了 URL Rewrite 模块。为了解决我在主项目中stopped web.config inheritance completely的问题。

      <location path="." inheritInChildApplications="false"> 
        <system.web> 
        … 
        </system.web> 
      </location>
    

    不确定这是否是您的问题,但这是一回事。

    【讨论】:

      【解决方案2】:

      尝试在 api 调用代码中将端口号附加到您的 url,如下所示

       url: 'http://ps-test.aars:9021/api/Item/GetArea'
      

      【讨论】:

        【解决方案3】:

        这取决于您在生产服务器上设置 IIS 应用程序的方式以及它响应的 URL。

        转到您的生产服务器,转到 IIS,找到您的应用程序,从 IIS 中打开它,它将在浏览器中打开,显示您设置使用的基本 URL。只需在其后添加其余部分。当您从部署 API 的实际服务器运行 API 时,这将起作用。

        然后你需要从你的机器上调用它,所以你需要确保你被允许从你的机器上点击它。如果不是,则需要打开端口并确保允许您的机器访问该生产服务器。

        恐怕从本地到生产我从不直截了当。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-04-15
          • 2021-03-22
          • 1970-01-01
          • 2012-09-21
          • 1970-01-01
          • 2012-08-06
          • 2017-11-12
          相关资源
          最近更新 更多