visual-studio VS2010 开发 Web 服务器不使用集成模式 HTTP 处理程序/模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2708187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:50:31  来源:igfitidea点击:

VS2010 development web server does not use integrated-mode HTTP handlers/modules

visual-studiohttphandlerweb-confighttpmodule

提问by Domenic

I am developing an ASP.NET MVC 2 web site, targeted for .NET Framework 4.0, using Visual Studio 2010.

我正在使用 Visual Studio 2010 开发一个针对 .NET Framework 4.0 的 ASP.NET MVC 2 网站。

My web.config contains the following code:

我的 web.config 包含以下代码:

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
        <add name="XhtmlModule" type="DomenicDenicola.Website.XhtmlModule" />
    </modules>
    <handlers>
        <add name="DotLess" type="dotless.Core.LessCssHttpHandler,dotless.Core" path="*.less" verb="*" />
    </handlers>
</system.webServer>

When I use Build > Publishto put the web site on my local IIS7 instance, it works great.

当我Build > Publish将网站放在本地 IIS7 实例上时,效果很好。

However, when I use Debug > Start Debugging, neither the HTTP handler nor module are executed on any requests.

但是,当我使用 时Debug > Start Debugging,HTTP 处理程序和模块都不会对任何请求执行。

Strangely enough, when I put the handler and module <add />tags back into <system.web />under <httpHandlers />and <httpModules />, they work. This seems to imply that the development web server is running in classic mode.

奇怪的是,当我将处理程序和模块<add />标签放回and<system.web />下时,它们起作用了。这似乎意味着开发 Web 服务器正在以经典模式运行。<httpHandlers /><httpModules />

How do I fix this?

我该如何解决?

回答by Sky Sanders

You don't. WebDev.WebServer.exedoes not and cannot support integrated pipeline.

你没有。WebDev.WebServer.exe不支持也不能支持集成管道。

So, if you have code that cannot be written to perform in both environments you will need to use a local IIS for development.

因此,如果您的代码无法在两种环境中执行,您将需要使用本地 IIS 进行开发。

Basically, system.webis the place to configure webdev server and IIS5-6 handlers and modules. system.webServeris for IIS7 handlers and modules, as you know.

基本上,system.web是配置 webdev 服务器和 IIS5-6 处理程序和模块的地方。system.webServer如您所知,用于 IIS7 处理程序和模块。

Reference:

参考

Each request in WebDev.WebHost40(and previous versions) is processed by HttpRuntime.ProcessRequest(which does not support integrated pipeline mode). This is the method used in all three versions of WebHost.WebServer.dll(the core of WebDev.WebServer.exe)

WebDev.WebHost40(及之前版本)中的每个请求都由HttpRuntime.ProcessRequest不支持集成管道模式)处理。这是WebHost.WebServer.dllWebDev.WebServer.exe的核心)三个版本都使用的方法

And the word of some dudewho is fairly familiar with the inner workings of Cassini/WebDev by virtue of managing this project. ;-)

还有一些通过管理这个项目对 Cassini/WebDev 的内部运作相当熟悉的家伙的话。;-)

回答by Bullines

I'm not sure if I'm too late in answering, but while it's known fact that the Cassini server doesn't support integrated pipeline mode, you can still test locally using the classic pipeline by adding it to the httpModules section of system.web in your web.config:

我不确定我的回答是否为时已晚,但虽然众所周知 Cassini 服务器不支持集成管道模式,但您仍然可以通过将经典管道添加到系统的 httpModules 部分来使用经典管道进行本地测试。 web.config 中的 web:

  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    .
    .
    .
    <!-- HTTP Modules using Classic Pipeline -->
    <httpModules>
      <add name="YourHttpModule" type="ACME.YourHttpModule"/>
    </httpModules>
  </system.web>

  <system.webServer>
    <!-- HTTP Modules using Integrated Pipeline -->
    <modules runAllManagedModulesForAllRequests="true">
      <add name="YourHttpModule" type="ACME.YourHttpModule"/>
    </modules>
  </system.webServer>

You'd probably want to remove the httpModules section from your production web.config.

您可能希望从生产 web.config 中删除 httpModules 部分。

回答by John

Got this today while running in visual studio 2012. Found the reason was visual studio launched the old web server that comes with 2010 and as explained above it can't work there. Changed to IIS Express by right click on properties, choose "Web" tab and and selecting IIS Express option. Then launching debug mode will start in IIS Express and this aparently supports operations such as Request.Headers.Addor whatever caused your exception.

今天在visual studio 2012中运行时得到了这个。发现原因是visual studio启动了2010年附带的旧Web服务器,如上所述它无法在那里工作。通过右键单击属性更改为 IIS Express,选择“Web”选项卡并选择 IIS Express 选项。然后启动调试模式将在 IIS Express 中启动,这显然支持诸如Request.Headers.Add或任何导致异常的操作。