c# - preCondition ="managedHandler"如何用于模块?

标签 c# asp.net iis

在阅读了一些关于集成管道的文档后,我对 IIS 如何确定何时运行托管模块、托管请求实际上是什么以及如何确定感到困惑,例如:

http://www.iis.net/learn/application-frameworks/building-and-running-aspnet-applications/aspnet-integration-with-iis http://blogs.msdn.com/b/tmarq/archive/2007/08/30/iis-7-0-asp-net-pipelines-modules-handlers-and-preconditions.aspx

多次提到“托管”请求。有一个实例解释了托管请求是一个映射到托管处理程序的请求。还有一句话说处理程序是一个“特殊”模块(第二个链接)。

模块被描述为针对每个 请求运行的东西,并且处理程序具有指定何时运行的映射(例如,*.aspx 的 HTTP GET)(第二个和第一个链接)。此外,对于模块,execute_request_handler [我假设它是处理程序实际运行的点] 出现在管道的几个阶段之后(在 begin_request、authenticate、authorize 等之后),这意味着有一个步骤发生在所有这一切之前,确定请求是针对托管处理程序的,以便在请求不是针对托管处理程序时禁用具有 preCondition="managedHanlder"的模块的执行。

我觉得这里缺少一些东西,有人可以阐明 preCondition="managedHandler"到底是如何工作的吗?

最佳答案

来自这篇博文 (http://blogs.iis.net/thomad/archive/2006/11/04/precondition-what.aspx):

The ManagedHandler precondition

IIS 7.0 introduces a new managed extensibility model. Handlers and Modules can now be written in managed code and directly integrated into the IIS request pipeline. But switching between managed and native code is an expensive operation. The managedHandler precondition was introduced to allow optimizing the performance of requests where no managed code needs to be involved, for example when static files (.html, .jpg etc.) are served. No managed code is called if the request is served by a native handler and every managed module is configured with the managedHandler precondition. A practical scenario is Forms authentication. The managed Forms authentication module has a managedHandler precondition and is therefore only called when ASP.NET content (e.g. *.aspx) pages are requested. If a .html page is requested the forms authentication is not called. If you want to protect all your content with forms authentication you can simply remove the managedHandler precondition from the Forms authentication module entry.

简而言之,如果请求可以由 native IIS 模块(例如图像)提供服务,则它不必经过所有托管管道(例如,所有“global.asax”事件和甚至更多),从而带来巨大的性能提升。

编辑:您问题的实际答案是:处理程序映射。这就是将文件扩展名关联到特定处理程序的原因。您将在下面找到如何在 II7 中编辑这些映射。您还可以找到有关处理程序映射的更多信息 here .

open this section in IIS

Then you will see all the registered mappings

关于c# - preCondition ="managedHandler"如何用于模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18989449/

相关文章:

c# - EF 6 连接池和存储的查询字符串 RAM 泄漏

c# - 将查询语法中的 LINQ 转换为 lambda 语法

c# - 子字符串值到多个文本框

c# - WebApi 中的异步方法导致 IIS ExecuteRequestHandler 挂起

Azure 上的 WCF 服务

c# - .NET 4.5 : internal error in the . NET 运行时 (80131506)/禁用并发 GC

asp.net - 如何完全隐藏搜索引擎的网站?

java - 使用自定义 key 和 IV 在 Android 和 .Net 中进行 AES 128 加密

c# - 如何验证内容页面中的复选框列表?

asp.net - IIS Web 服务器中的此错误(扩展配置)是什么?