HTTP请求未到达IIS模块

3
在开发一个基本身份验证的IIS模块时,我遇到了问题。当浏览网页时,该模块运行良好,但是调用Web服务时似乎请求没有到达模块,并且一些中间模块控制了该请求。
通过使用Fiddler,我发现当HTTP请求头中的Content-type设置为application/json时,中间模块/处理程序会触发。所以以下请求不起作用:
当正常工作时,服务器应该要求客户端通过在响应中设置WWW-Authenticate标头发送用户凭据。
GET /WebServices/service.asmx/someMethod?param=test HTTP/1.1
Host: localhost
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Content-Type: application/json

asdfasdf
asdfasdfasdf

响应:请注意响应中的jsonerror标头

HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
jsonerror: true
X-Powered-By: ASP.NET
Date: Mon, 11 Mar 2013 23:49:02 GMT
Content-Length: 105

{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.In
validOperationException"}

这个可以正常工作:请注意没有content-type


(注:原文中的英文单词和标点符号已经正确翻译,保留了HTML标签)
GET /WebServices/service.asmx/someMethod?param=test HTTP/1.1
Host: localhost
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

asdfasdf
asdfasdfasdf

正确的回应是:注意响应中的WWW-Authenticate

HTTP/1.1 401 Unauthorized
Location: http://localhost/WebServices/service.asmx/someMethod?param=test
Server: Microsoft-IIS/7.5
WWW-Authenticate: Basic
X-Powered-By: ASP.NET
Date: Mon, 11 Mar 2013 23:59:48 GMT
Content-Length: 0
1个回答

1

嗯,那个中间模块是ScriptModule,在配置中添加了3.5和4.0版本。通过dotpeek检查它们,我发现脚本模块会检查请求的content-type是否为application/json,然后尝试将请求处理为REST请求或Web服务调用。

移除它们后,没有发生什么特别的事情。我认为它们是在使用脚本管理器或Microsoft特定的AJAX服务时使用的。您可以在ASP.Net Ajax编程技巧中找到更多信息。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接