-1

I created asp.net webApi and publish in somee.com. I type link xxxx.somee.com/api/xxxx is ok. But I call in Angularjs not run

$http.get('http://xxxxxx.somee.com/api')
.then(function(response) {
    console.log(response);
});

I received error:

XMLHttpRequest cannot load xxxx.somee.com/api/xxxx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

Please give the solutions. Thank you very much.

Nam Le
  • 53
  • 1
  • 4
  • Please try searching that specific error before asking. There are thousands of questions about it on this site and all over the web – charlietfl Dec 13 '16 at 03:14

1 Answers1

0

If your Angular website and API websites are running in a different domain or with ports this issue will happen. To resolve this please add the following code into your webapiconfig.cs file.

 var cors = new EnableCorsAttribute(http(s):// xxxx.somee.com/api/xxxx, "*", "*");
 config.EnableCors(cors);
Kalyan
  • 1,200
  • 1
  • 11
  • 23