方法Delete不被访问控制允许的方法允许误差 [英] Method DELETE is not allowed by Access-Control-Allow-Methods error
本文介绍了方法Delete不被访问控制允许的方法允许误差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经开发利用angularjs当我尝试写一个删除使用$资源就会给我下面的错误前端到RESTAPI
i have developed a front end to a RESTAPI using angularjs when i try to write a DELETE using $resource it will give me following error
方法删除不被访问控制允许的方法允许的。
Method DELETE is not allowed by Access-Control-Allow-Methods.
推荐答案
我也做与棱角分明的东西,但我希望这可以帮助你。这里是一个解决方案:
首先在你的API web.config文件,更新
I am also doing the something with angular but I hope this may help you. Here is a solution: First have to update in your API web.config file
<clear />
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
<add name="Access-Control-Allow-Methods" value="OPTIONS,GET,POST,PUT,DELETE" />
In `ApiController`
[HttpDelete]
public string Delete()
{
return "u call delete";
}
public HttpResponseMessage Options() {
var response = new HttpResponseMessage();
response.StatusCode = HttpStatusCode.OK;
return response;
}
In Angular...
home.post().then(function (data) {
console.log(data);
});
home.remove().then(function (data) {
console.log(data);
});
Out Put...
> u call delete
Hope this will help you.. :)
这篇关于方法Delete不被访问控制允许的方法允许误差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文