OPTIONS 预检请求未到达 IIS 托管服务

Dea*_*bit 4 iis wcf iis-7 cors http-status-code-404

我有一个本地主机网站和一个 IIS(7.5) 托管的 WCF 服务,它是这样实现的,并附加了一个 Visual Studio 调试器。每当我向我的服务发出 CORS 请求时,我都会收到以下 404 响应以及标准的 ASP.Net 错误页面:

OPTIONS http://192.168.200.44/api/values HTTP/1.1
Host: 192.168.200.44
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Origin: http://localhost:51946
Access-Control-Request-Method: POST
Access-Control-Request-Headers: content-type
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache

Response >>
HTTP/1.1 404 Not Found
Content-Type: text/html
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
Date: Thu, 26 Sep 2013 09:38:49 GMT
Content-Length: 1245
Run Code Online (Sandbox Code Playgroud)

Originally I was receiving erroneous 200 messages which didn't touch my WCF applictions numerous breakpoints, so it was being handled by IIS itself. I then followed this and this SO posts and removed the OPTIONSVerbHandler from the site and add "OPTIONS, PUT, POST & DELETE" as allowed HTTP verbs in the IIS manager UI (rather then web.conf), which progressed me to my 404 message. I've looked into WebDav which is highlighted as a problem but I haven't disabled/removed it because I don't know how but have read that it only affects "PUT & DELETE" operations where as my "POST" ops are also failing.

GET requests work as expected so the service definitely exists/works in IIS, just the Options preflight isn't reaching my service.

TY

Mor*_*ael 5

尽管 OP 设法找到了适用于他们特定情况的解决方案,但在过去的几个小时里,同样的问题一直困扰着我。就我而言,我知道这不是代码/web.config 问题,因为相同的代码在我的本地 IIS 上运行得非常好,但在生产版本上却没有。

在阅读了大量帖子并尝试了他们建议的所有内容(包括 OP 的答案)后,我实际上开始查看 IIS 日志(应该先这样做!)并发现:

2015-03-09 14:43:39 <IP Addr> GET /Rejected-By-UrlScan ~/Service.svc/H2dbImportTxtFile <Port> - <IP Addr>
Run Code Online (Sandbox Code Playgroud)

这也导致我:

http://www.pressthered.com/rejected-by-urlscan_404_errors/

最终 [AllowVerbs] 部分:

\system32\inetsrv\urlscan\UrlScan.ini

我只需要添加选项。

现在 OPTIONS 请求通过了,一切正常。

希望能帮助其他被逼疯的人。

编辑:

正如另一篇 SO 帖子中所述(恐怕我现在已经丢失了),由于我的是 WCF 服务,因此我还必须将侦听服务的界面从以下位置更改:

[WebInvoke(Method = "POST", etc]

[WebInvoke(Method = "*", etc]