我在客戶端使用AngularJS $ http來訪問服務器端的ASP.NET Web API應用程序的端點。由於客戶端與服務器位於不同的域中,因此我需要CORS。它適用於$ http.post(url,data)。但只要我驗證用戶,並通過$ http.get(URL)的請求,我得到的消息'Access-Control-Allow-Origin'標頭包含多個值
The 'Access-Control-Allow-Origin' header contains multiple values 'http://127.0.0.1:9000, http://127.0.0.1:9000', but only one is allowed. Origin 'http://127.0.0.1:9000' is therefore not allowed access.
提琴手讓我發現,確實有獲取請求兩個頭項後一個成功的選擇請求。什麼和我在哪裏做錯了什麼?
更新
當我使用jQuery $不用彷徨,而不是$ http.get,出現相同的錯誤消息。所以這對於AngularJS來說似乎沒有問題。但是哪裏錯了?
看起來你正在從設置文件中讀取Properties.Settings.Default.Cors。你能舉一個例子嗎? UseCors是什麼類? – Hoppe
「Uncaught ReferenceError:EnableCorsAttribute is not defined」?? – circuitry
@Hoppe,請查看http://msdn.microsoft.com/en-us/library/dn314597(v=vs.118).aspx。它解釋說,EnableCorsAttribute的第一個參數是允許的起點。例如「*」允許所有。 –