my project is : ASP.NET Web Api C# With Angular
i am trying to make simple http get with allow cross domains from angular client
the request :
$http.defaults.headers.common['X-Auth-Key'] = 'somekey';
$http.defaults.headers.common['X-Auth-Email'] = 'someuser';
$http.defaults.headers.common['Access-Control-Allow-Origin'] = '*';
$http.defaults.headers.common['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS';
return {
GetDomains: function () {
return $http({
method: "get",
url: "https://api.cloudflare.com/client/v4/zones/cd7d068de3012345da9420df9514dad0/dns_records?page=3&per_page=20&order=type&direction=asc",
responseType: 'json'
}).then(function mySucces(response) {
return response.data;
})
}
}
});
in the response i can see :
access-control-request-headers:access-control-allow-methods, access-control- allow-origin, x-auth-email, x-auth-key
and the error :
XMLHttpRequest cannot load https://api.cloudflare.com/client/v4/zones/cd7d068de3012345da9420df9514dad0/dns_records?page=3&per_page=20&order=type&direction=asc. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 400.
i am trying to do it with iis express with visual studio 2015
IIS Express applicationhost.config and Web.Config files have :
<httpProtocol>
<customHeaders>
<clear />
<add name="X-Powered-By" value="ASP.NET" />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Accept, X-Access-Token, X-Application-Name, X-Request-Sent-Time"/>
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS"/>
<add name="Access-Control-Allow-Credentials" value="true"/>
</customHeaders>
<redirectHeaders>
<clear />
</redirectHeaders>
</httpProtocol>
App_Start / WebApiConfig.cs file :
var corsAttr = new EnableCorsAttribute("https://api.cloudflare.com", "*", "*");
config.EnableCors(corsAttr);
and still the same error
i tried everything may be you can help me
thank you !