【发布时间】:2016-09-09 02:09:07
【问题描述】:
在 Visual Studio 中,我有两个应用程序。一个是 Angular 2 网站,另一个是 WebApi 项目。我在 WebAPI 方法中有一个断点,当 Angular 服务尝试检索数据但页面上没有显示任何内容时,该断点会被命中。打开浏览器控制台出现以下错误:
XMLHttpRequest cannot load http://localhost:58949/api/people. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:62761' is therefore not allowed access.
解决此问题的最佳方法是什么?我通过创建一个同时托管 WebAPI 和 Angular 应用程序的 MVC 应用程序来完成这项工作,但我不喜欢这个解决方案。
【问题讨论】:
标签: c# asp.net asp.net-web-api angular