自定义异步HTTP处理程序仅在IIS 7.5集成模式下生成错误500 - 为什么?

时间:2014-04-16 14:57:51

标签: c# asp.net iis asynchronous httphandler

我在ASP.Net上写了一个长期投票项目。客户端为一个页面创建XMLHttpRequest,该页面是" any.orders"或者" any.prices"。

我有几个异步自定义http处理程序,它们接收请求,执行请求订阅,并在稍后的时间点提供数据(概念上,页面响应)。

在Visual Studio的开发服务器中,它运行良好,完美。在Windows Server 2008 R2上的IIS 7.5中,我只能让它在经典模式下工作。

如果我切换到集成模式(带有请求跟踪),XMLHttpRequest会从IsapiModule获取错误500:

ModuleName:IsapiModule 
Notification:128 
HttpStatus:500 
HttpReason:Internal Server Error 
HttpSubStatus:0 
ErrorCode:0 
ConfigExceptionInfo:
Notification:EXECUTE_REQUEST_HANDLER 
ErrorCode:The operation completed successfully. (0x0) 

在应用程序日志中,我可以看到正在创建的Async处理程序类的实例,但未调用BeginProcessRequest()函数。几乎就像IsapiModule在没有处理页面请求的情况下立即击退零返回代码一样。

我一直在疯狂地试图让它在集成模式下工作。我知道长时间轮询的日子已经过时,因为WebSockets接近标准,但如果我能清楚这一点,它将有助于我了解正在发生的事情。

处理程序注册的web.config部分如下:

  <system.web>

    <!-- IIS 6.0/7.0 AsyncHttpHandler Registration -->
    <httpHandlers>

      <add verb="*" path="*.prices" type="AsyncHttpHandlerPrices" />
      <add verb="*" path="*.orders" type="AsyncHttpHandlerOrders" /> 

      <!-- For Copy and Paste into Excel -->
      <add verb="*" path="*.xls" type="System.Web.StaticFileHandler" />
      <add verb="*" path="*.xlsx" type="System.Web.StaticFileHandler" />

    </httpHandlers>

  </system.web>

  <system.webServer>

    <handlers>
    <remove name="svc-Integrated" />
      <remove name="xoml-Integrated" />
      <add name="*.vbhtml_*" path="*.vbhtml" verb="*" type="System.Web.HttpForbiddenHandler" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="*.vbhtm_*" path="*.vbhtm" verb="*" type="System.Web.HttpForbiddenHandler" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="*.cshtml_*" path="*.cshtml" verb="*" type="System.Web.HttpForbiddenHandler" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="*.cshtm_*" path="*.cshtm" verb="*" type="System.Web.HttpForbiddenHandler" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="*.aspq_*" path="*.aspq" verb="*" type="System.Web.HttpForbiddenHandler" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="*.xamlx_*" path="*.xamlx" verb="*" type="System.Xaml.Hosting.XamlHttpHandlerFactory, System.Xaml.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="*.xoml_*" path="*.xoml" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="*.svc_*" path="*.svc" verb="*" type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="*.soap_*" path="*.soap" verb="*" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="*.rem_*" path="*.rem" verb="*" type="System.Runtime.Remoting.Channels.Http.HttpRemotingHandlerFactory, System.Runtime.Remoting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="*.asmx_*" path="*.asmx" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="ScriptResource.axd_GET,HEAD" path="ScriptResource.axd" verb="GET,HEAD" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="*_AppService.axd_*" path="*_AppService.axd" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="eurl.axd_*" path="eurl.axd" verb="*" type="System.Web.HttpNotFoundHandler" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="*.xlsx_*" path="*.xlsx" verb="*" type="System.Web.StaticFileHandler" preCondition="integratedMode,runtimeVersionv2.0" />
      <add name="*.xls_*" path="*.xls" verb="*" type="System.Web.StaticFileHandler" preCondition="integratedMode,runtimeVersionv2.0" />
      <add verb="*" path="*.prices" name="AsyncHttpHandlerPrices" type="AsyncHttpHandlerPrices" modules="IsapiModule" scriptProcessor="c:\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll" />
      <add verb="*" path="*.orders" name="AsyncHttpHandlerOrders" type="AsyncHttpHandlerOrders" modules="IsapiModule" scriptProcessor="c:\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll" />
    </handlers>
    <modules>
      <remove name="ServiceModel" /> 
      <add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule, System.Web.Mobile, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" preCondition="managedHandler" />
      <add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
    </modules>
    <validation validateIntegratedModeConfiguration="false" />
    <tracing>
      <traceFailedRequests>
        <add path="*.orders">
        <traceAreas>
        <add provider="ASP" verbosity="Verbose" />
        <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
        <add provider="ISAPI Extension" verbosity="Verbose" />
        <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,Rewrite,RequestRouting" verbosity="Verbose" />
        </traceAreas>
        <failureDefinitions statusCodes="100-999" />
        </add>
        <add path="*.prices">
        <traceAreas>
        <add provider="ASP" verbosity="Verbose" />
        <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
        <add provider="ISAPI Extension" verbosity="Verbose" />
        <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,Rewrite,RequestRouting" verbosity="Verbose" />
        </traceAreas>
        <failureDefinitions statusCodes="100-999" />
        </add>
      </traceFailedRequests>
    </tracing>
  </system.webServer>

DotNet版本是4.0。安装.Net可扩展性功能(如上所述,它在经典模式下工作,所以一定很好)。

1 个答案:

答案 0 :(得分:4)

问题是,如果没有web.config中相应的更改,无法从经典模式切换到集成模式。如果我是在正确的方式,这必须是您收到的错误:

  

检测到的ASP.NET设置不适用于集成管理管道模式

基本上,ASP.NET会验证web.config中的正确配置,如果配置文件的设置不适用,则会返回500错误。你有两种方法可以做到:

第一种方法是禁用 ASP.NET执行验证集成模式配置的验证。

<configuration>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
    </system.webServer>
</configuration> 

第二个是迁移配置设置。本文档非常有用:http://msdn.microsoft.com/library/bb515251.aspx

<强>更新

我专注于问题而不是你的问题(为什么?)。这就是为什么:http://mvolo.com/breaking-changes-for-aspnet-20-applications-running-in-integrated-mode-on-iis-70/

我希望你觉得它很有用

更新2:

在这里,您有两个SO问题以及关于同一问题的非常好的答案:

HTTP Error 500.22 - Internal Server Error (An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.)

An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode