I am trying to connect to an ASP.NET Web-API web service from an AngularJS page, and I get the following
Credentials flag, but the header 'Access-Control-Allow-Credentials' is equal to ''. It must be "true" to allow credentials. The origin of
http: // localhost: 221 'is therefore not allowed.
var cors = new EnableCorsAttribute("http://localhost:221", "*","GET,PUT,POST,DELETE"); config.EnableCors(cors);
Using this AngularJS
$http({ method: 'GET', url: 'http://localhost:1980/api/investors/62632', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, withCredentials: true // withCredentials: true, }).then(function onUserComplete(response) { // this callback will be called asynchronously // when the response is available }, function onError(response) { // called asynchronously if an error occurs // or server returns response with an error status.
After reading many articles, I add this to web.config
<httpProtocol> <customHeaders> <add name="Access-Control-Allow-Origin" value="http://localhost:221" /> </customHeaders> </httpProtocol>
and I get this error message
The header "Access-Control-Allow-Origin" contains several localhost: 221, localhost: 221 values, but only one is allowed. Therefore, the location of localhost: 221 is not allowed.
Which really makes no sense since I added it once and it does not find it, but I add it to web.config and I get an error message adding it several times. I have read many articles and cannot find the correct answer. I am using Google Chrome. I would be very grateful for the help, as I am now taking out my hair.