CORS的PUT支持和配合的ASP.NET Web API DELETE [英] CORS support for PUT and DELETE with ASP.NET Web API
问题描述
我用的ASP.NET Web API的最终版本着手实施一个JavaScript友好的API。每各种教程,我在我的web.config启用CORS:
I am working with the final version of ASP.NET Web API to implement a JavaScript-friendly API. Per various tutorials, I have enabled CORS in my web.config:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
有了上面,跨域GET和POST请求做工精细,但PUT和DELETE请求都失败。
With the above, cross-domain GET and POST requests work fine, but PUT and DELETE requests both fail.
在Chrome浏览器:
In Chrome:
put方法不被访问控制允许的方法允许的。
Method PUT is not allowed by Access-Control-Allow-Methods.
方法Delete没有被访问控制允许的方法允许的。
Method DELETE is not allowed by Access-Control-Allow-Methods.
有没有得到PUT和DELETE动词工作跨域需要额外的东西?
Is there something additional required to get PUT and DELETE verbs working cross-domain?
推荐答案
看起来又增加自定义头整理出来:
It looks like adding another custom header sorted it out:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
</customHeaders>
</httpProtocol>
</system.webServer>
这篇关于CORS的PUT支持和配合的ASP.NET Web API DELETE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!