2013-03-12 117 views
1

在为基本身份验证开发IIS模块的过程中,我遇到了一个问题。该模块在浏览页面时工作正常,但在调用Web服务时,似乎请求没有到达模块,并且一些中间模块控制了请求。HTTP请求未到达IIS模块

使用提琴手时,我发现当在http请求头设置为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

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

嗯,这在中间人模块是ScriptModule在那里我们有在配置中添加3.5和4.0版本。通过dotpeek检查他们,我发现脚本模块检查请求content-type不是application/json,然后尝试将请求作为REST请求或web服务调用处理。

通过删除它们,没有什么特别的事情发生。我假定在使用脚本管理器或Microsoft Specific AJAX服务时要使用它们。你可以在 ASP.Net Ajax Programming Tricks