【发布时间】:2012-09-13 08:14:13
【问题描述】:
我正在使用 ASP.NET Web API 的最终版本来实现对 JavaScript 友好的 API。根据各种教程,我在 web.config 中启用了 CORS:
<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 请求都失败。
在 Chrome 中:
Access-Control-Allow-Methods 不允许方法 PUT。
Access-Control-Allow-Methods 不允许方法 DELETE。
让 PUT 和 DELETE 动词跨域工作是否需要额外的东西?
【问题讨论】:
-
你是如何在 webconfig 中启用 CORS 的?
-
你也有一个全局 CORS 处理程序吗?还是您仅在 web.config 中修复了 CORS?
-
我只在 web.config 级别实现了这个。
标签: asp.net cross-domain asp.net-web-api cors