2016-12-13 5 views
-1

私はasp.net webApiを作成し、somee.comで公開しました。私はリンクxxxx.somee.com/api/xxxxを入力しても問題ありません。しかし、私はエラーを受け取っ問題AngularjsとWebApiで「XMLHttpRequestを読み込めません」という問題

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

を実行していないAngularjsに呼び出す:

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.

ソリューションをお願いします。どうもありがとうございました。

+0

質問する前に特定のエラーを検索してください。このサイトやウェブ上には数千もの質問があります – charlietfl

答えて

0

AngularウェブサイトとAPIのウェブサイトが異なるドメインまたはポートで動作している場合、この問題が発生します。 これを解決するには、webapiconfig.csファイルに次のコードを追加してください。

var cors = new EnableCorsAttribute(http(s):// xxxx.somee.com/api/xxxx, "*", "*"); 
config.EnableCors(cors); 
関連する問題