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

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

当配置 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/

相关文章:

html - DOM 顺序是否确定张贴的表单参数的顺序?

asp.net-web-api - AngularJS + ASP.NET Web API 跨域问题

asp.net-web-api - 设置默认 WebAPI 格式化程序

asp.net - 在Windows身份验证之前拦截HTTP OPTIONS ASP.NET Core 2.0

jquery - SignalR 1.0.1 使用 Chrome 的跨域请求 (CORS)

http - 为什么 HTTP 使用 TCP?

windows - 在主机文件中指定 IP 与直接使用 IP 之间的区别

javascript - 如何在 json-server 上添加 header ?

html - 如何向路由器发送格式不正确的 HTTP 请求?

iis-7.5 - 启用 Windows 身份验证的 IIS 中 CORS 请求的 401 响应