在我的C# web api上,我启用了cors,即
[EnableCors(origins: "*", headers: "*", methods: "*")]
然后在我的angular js站点中,我调用post API。
authService.login = function (credentials) {
return $http
.post(WEB_CONFIG.login, credentials)
.then(function (res) {
Session.create(res.data.Email, res.data.Roles,res.data.Username);
return res.data.user;
});
};
angular站点发出来自localhost:9000的请求,而API位于localhost
获取错误
XMLHttpRequest无法加载http://localhost/mysite/api/user/login。对印前检查请求的响应未通过访问控制检查:请求的资源上不存在“access - control -Allow-Origin”标头。因此不允许访问源'http://localhost:9000‘。
为什么在启用Cors的情况下会出现此错误?
发布于 2017-07-25 02:59:06
尝试此配置。
cors:
allowed-origins: "*"
allowed-methods: GET, PUT, POST, DELETE, OPTIONS
allowed-headers: "*"
exposed-headers:
allow-credentials: true
max-age: 1800
https://stackoverflow.com/questions/34272946
复制相似问题