【发布时间】:2017-11-12 02:53:36
【问题描述】:
我使用 vs 2017 创建一个包含两个项目的解决方案:
- 1- 网络接口
- 2- 通过 Angular 服务访问 WebApi 控制器的 Asp .Net Core Web 应用程序。
我有一个 Web Api 控制器
[Route("api/[controller]/[action]")]
public class ClientController : Controller
{
// GET: api/Client/Get
[HttpGet]
public JsonResult Get()
{
ClientQuery _Query = new ClientQuery();
List<ClientLisModel> _Results = _Query.GetAll();
return new JsonResult(_Results);
}
在我的角度服务中,我创建了一个函数来访问这个控制器操作:
this.getListeClient = function getListeClient() {
var deferred = $q.defer();
$http({
method: 'GET',
url: '/api/Client/Get'
})
.then(function (data) {
deferred.resolve(data);
})
.catch(function (msg, code) {
deferred.reject(msg);
$log.error(msg, code);
});
return deferred.promise;
}
当我从 vs 2017 运行我的应用程序时,一切正常。但是当我在 iis 7.5 中将它部署到 MyWebSite 时。我有这个错误:
GET http://localhost/api/Client/Get 404(未找到)
它应该寻找http://localhost/MyWebSite/api/Client/Get
我的 Web.config 是:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\Application.UI.Web.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
谢谢!
【问题讨论】:
标签: angularjs asp.net-web-api asp.net-core-1.1