在IE8和9我收到的时候我做了CORS的WebAPI调用下面的JavaScript错误:IE9,IE8与AngularJS CORS返回“访问被拒绝” - ASP.NET的WebAPI
Error: Access is denied.
{
[functions]: ,
description: "Access is denied.",
message: "Access is denied.",
name: "Error",
number: -2147024891
}
我设置我的的WebAPI喜欢这里描述http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api
所以的WebAPI包含:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
[...]
我的测试AngularJS应用:
个<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ng="http://angularjs.org" ng-app="app">
<head>
<title>test</title>
<script src="Scripts/angular.js"></script>
<script src="app.js"></script>
</head>
<body>
<div ng-controller="testController as vm">
{{vm.test}}
{{vm.data}}
</div>
</body>
</html>
app.js:
var app = angular.module('app');
app.controller('testController', function ($http) {
var vm;
vm = this;
vm.test = "bla non no ";
vm.data = null;
$http.defaults.headers.common['Authorization'] = 'a token'
return $http({
method: 'GET',
data: null,
url: 'http://webapi.com/api/controller/getactionmethod/',
}, function (data) {
console.log("bla");
}).success(function (data, status, headers, config) {
console.log("bla a");
vm.data;
});
});
上面的代码/调用的WebAPI铬和IE 10. IE10打印作品:
SEC7118:XMLHttpRequest进行http://webapi.com/api/controller/getactionmethod/需要跨源资源共享(CORS)。 SEC7119:XMLHttpRequest的http://webapi.com/api/controller/getactionmethod/需要CORS预检。
我真的被卡住了,不知道我可以试试其他的东西。有任何想法吗?
http://stackoverflow.com/questions/10232017/ie9-jquery-ajax-with-cors-returns-access-is-denied – epascarello 2014-10-10 16:48:53
我使用的是angularjs而不是jQuery。 – Briefkasten 2014-10-10 16:50:04
IE8和IE9不支持标准的CORS XHR。看到我对这个问题的答案更多信息http://stackoverflow.com/questions/25141650/xdomainrequest-vs-xmlhttprequest – MrCode 2014-10-10 16:57:35