【发布时间】:2014-06-16 02:39:29
【问题描述】:
我正在与 David Antramian 的 spa-authentication-example 合作。除了我使用 n 层方法并将我的数据/模型与 Web API 项目分开之外,我明确地遵循了他的示例。
当使用 Postman 并直接针对 API Web 应用程序时,一切正常:
但不是当我使用客户端 UI 时(我确实更改了 angularjs 的 user.js/salesdata.js 中的 url 以反映 2604 端口),不太好:
我试过“app.UseCors(CorsOptions.AllowAll);”在我的 Startup.Auth.cs 中无济于事。
在我的 API web.config 中也试过了,还是不行:
<httpProtocol>
<customHeaders>
<!-- Enable Cross Domain AJAX calls -->
<remove name="Access-Control-Allow-Origin" />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
考虑可能是 Chrome 相关的安全问题,我也在 IE 中尝试过,但无济于事。
有什么想法吗?
这是我完整的post方法,和Postman是一样的:
this.authenticate = function(username, password, successCallback, errorCallback, persistData) {
this.removeAuthentication();
var config = {
method: 'POST',
url: 'http://localhost:2604/token',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
data: 'grant_type=password&username=' + username + '&password=' + password,
};
【问题讨论】:
标签: angularjs cors asp.net-identity