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

时间:2015-10-01 19:06:16

标签: http asp.net-web-api cors owin

当配置CORS(并且看似正在工作)时,它仍会为OPTIONS动词返回405。

通过Owin NuGet软件包Microsoft.Owin.Cors配置CORS,它似乎返回正确的标头。

当我伪造预检OPTIONS请求时,我注意到Fiddler中的问题。当我提议我从一个允许的域名进行呼叫时,标题会正确返回,如果我提出其他域名,它们就会正确缺席 - 它正在运行。

但为什么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: http://localhost:12345 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Thu, 01 Oct 2015 18:59:32 GMT Content-Length: 96

<Error><Message>The requested resource does not support http method 'OPTIONS'.</Message></Error>

注意<Error><Message>The requested resource does not support http method 'OPTIONS'.</Message></Error>存在,所以我猜浏览器会好的,或者浏览器是否会被推迟#39}。由否定的405?

2 个答案:

答案 0 :(得分:0)

在解决另一个问题的同时,我对整个Microsoft.Owin.Cors进行了反向设计以逐步完成它。

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

所以,如果你得到405,那么仔细检查。

答案 1 :(得分:-1)

我想你可以先检查一下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>