当配置 CORS(并且看似工作)时,它仍会为 OPTIONS 谓词返回 405。
CORS 通过 Owin NuGet 包配置,Microsoft.Owin.Cors
它似乎返回了正确的 header 。
当我伪造预检 OPTIONS 请求时,我注意到 Fiddler 中的问题。当我建议我从一个允许的域调用时, header 会正确返回,如果我建议一些其他域,它们会正确地不存在 - 它正在工作。
但为什么是 405?
HTTP/1.1 405 Method Not Allowed
Cache-Control: no-cache
Pragma: no-cache
Allow: GET,PUT,DELETE
Content-Type: application/xml; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
Access-Control-Allow-Origin: <a href="http://localhost:12345" rel="noreferrer noopener nofollow">http://localhost:12345</a>
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 01 Oct 2015 18:59:32 GMT
Content-Length: 96
<code><Error><Message>The requested resource does not support http method 'OPTIONS'.</Message></Error></code>
注意 Access-Control-Allow-Origin
存在,所以我猜浏览器会好起来的,或者浏览器会被否定的 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>
关于http - CORS - ...不支持 http 方法 'OPTIONS',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32895013/