【问题标题】:Http Request not reaching the IIS moduleHttp 请求未到达 IIS 模块
【发布时间】:2013-03-12 00:03:11
【问题描述】:

在开发用于基本身份验证的 IIS 模块期间,我遇到了一个问题。该模块在浏览页面时工作正常,但在调用 web-services 时,请求似乎没有到达模块,并且一些中间模块控制了请求。

使用提琴手,我发现当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

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

【问题讨论】:

    标签: asp.net iis-7 http-headers content-type


    【解决方案1】:

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

    删除它们后,并没有发生什么特别的事情。我假设它们将在使用脚本管理器或 Microsoft 特定 AJAX 服务时使用。你可以找到更多关于它 ASP.Net Ajax Programming Tricks

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-20
      • 2018-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-02
      • 2011-09-28
      • 2018-01-05
      相关资源
      最近更新 更多