在服务器中部署后未找到 Web api
Web api not found after deployed in server
我已经在测试服务器上部署了(使用端口 9021 和站点名称 Production)Angularjs Web API 应用程序,当我点击 URL
http://localhost:9021/api/Item/GeAreas?P_Id=US99
在测试服务器上,我成功地从网络上得到了响应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>
当我点击 URL 时:
http://ps-test.aars/Production/Summary.html?P_Id=US99
在我的本地系统上,出现错误:
Failed to load resource: the server responded with a status of 404 (Not Found) /api/Item/GetAreas?P_Id=US99
不确定是什么问题。
这取决于您如何在生产服务器上设置 IIS 应用程序以及 URL 它响应什么。
转到您的生产服务器,转到 IIS,找到您的应用程序,从 IIS 打开它,它会在浏览器中打开,向您显示它的基础设置 URL 以供使用。只需在其后添加其余部分即可。当您 运行 从部署到的实际服务器 API 时,这将起作用。
然后你需要从你的机器上调用它,所以你需要确保你可以从你的机器上点击它。如果不是,则需要打开端口并确保允许您的计算机访问该生产服务器。
恐怕从本地到生产我从来没有直截了当。
尝试将端口号附加到 api 调用代码中的 url,如下所示
url: 'http://ps-test.aars:9021/api/Item/GetArea'
生产服务器上是否有任何其他 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>
不确定这是否是您的问题,但这是一回事。
我已经在测试服务器上部署了(使用端口 9021 和站点名称 Production)Angularjs Web API 应用程序,当我点击 URL
http://localhost:9021/api/Item/GeAreas?P_Id=US99
在测试服务器上,我成功地从网络上得到了响应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>
当我点击 URL 时:
http://ps-test.aars/Production/Summary.html?P_Id=US99
在我的本地系统上,出现错误:
Failed to load resource: the server responded with a status of 404 (Not Found) /api/Item/GetAreas?P_Id=US99
不确定是什么问题。
这取决于您如何在生产服务器上设置 IIS 应用程序以及 URL 它响应什么。
转到您的生产服务器,转到 IIS,找到您的应用程序,从 IIS 打开它,它会在浏览器中打开,向您显示它的基础设置 URL 以供使用。只需在其后添加其余部分即可。当您 运行 从部署到的实际服务器 API 时,这将起作用。
然后你需要从你的机器上调用它,所以你需要确保你可以从你的机器上点击它。如果不是,则需要打开端口并确保允许您的计算机访问该生产服务器。
恐怕从本地到生产我从来没有直截了当。
尝试将端口号附加到 api 调用代码中的 url,如下所示
url: 'http://ps-test.aars:9021/api/Item/GetArea'
生产服务器上是否有任何其他 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>
不确定这是否是您的问题,但这是一回事。