CORS - ...不支持 http 方法 'OPTIONS'

CORS - ...does not support http method 'OPTIONS'

配置 CORS 后(似乎可以正常工作)它仍然 return OPTIONS 动词为 405。

CORS 是通过 Owin NuGet 包配置的,Microsoft.Owin.Cors 似乎 return 正确 headers。

我在伪造预检选项请求时注意到 Fiddler 中的问题。 headers 当我建议我从允许的域调用时正确返回,如果我建议其他域它们正确地不存在 - 它的工作。

但为什么是 405?

HTTP/1.1 405 方法不允许 Cache-Control: no-cache 编译指示:no-cache 允许:获取、放置、删除 Content-Type: application/xml;字符集=utf-8 过期:-1 服务器:Microsoft-IIS/8.0 Access-Control-Allow-Origin: <a href="http://localhost:12345" rel="nofollow">http://localhost:12345</a> X-AspNet-Version:4.0.30319 X-Powered-By: ASP.NET 日期:2015 年 10 月 1 日星期四 18:59:32 GMT Content-Length: 96</p> <p><code><Error><Message>The requested resource does not support http method 'OPTIONS'.</Message></Error>

注意 Access-Control-Allow-Origin 存在,所以我猜浏览器会没问题,或者浏览器会被 'put off' 否定 405?

我想你可以检查 IIS 配置中第一个允许的动词设置。

参考http://www.iis.net/configreference/system.webserver/security/requestfiltering/verbs

  • web.config 例子 <configuration> <system.webServer> <security> <requestFiltering> <verbs applyToWebDAV="false"> <add verb="PUT" allowed="false" /> </verbs> </requestFiltering> </security> </system.webServer> </configuration>

在处理另一个问题时,我对整个 Microsoft.Owin.Cors 进行了逆向工程以逐步解决它。

事实证明,如果中间件已经处理了 OPTIONS 请求,那么它应该 return 一个 2xx,事实上,有了新的知识,即中间件需要在请求中看到什么来确定它是CORS 预检请求,我能够在 Fiddler 中伪造一个并获得 2xx。

所以,如果你得到 405,那么 double-check。