【发布时间】:2021-12-31 03:21:17
【问题描述】:
我正在使用 firefox 在 AngularJS/HTML 客户端页面和 ASP.NET WebAPI 上的控制器之间执行连接。
问题是我不断收到“跨源请求被阻止:同源策略不允许在 https://localhost:44377/project/all 读取远程资源。(原因:CORS 标头 'Access-Control- Allow-Origin' 缺失)。”除非我启用 CORS firefox 扩展。
即使启用了该功能,我的页面似乎也没有获取所需的数据;但错误消失了。
[EnableCors(origins: "https://localhost:PortNumberHereWithoutTheForwardSlah", headers: "", methods: "")] 在我的 Controller:ApiController 上方并使用了 config.EnableCors();在 App_Start 的 WebApi.Config 中。
注意:当我尝试在浏览器中使用时,使用 [HttpGet] 的方法确实有效。
【问题讨论】:
-
不,我在 ASP.net MVC 上
标签: asp.net angularjs asp.net-mvc-4 asp.net-web-api