简体   繁体   English

IIS 7.5集成管道对asp.net的请求

[英]IIS 7.5 integrated pipeline filter requests for asp.net

Can I somehow send to ASP.NET part only request that matches some pattern? 我可以以某种方式将匹配某种模式的请求发送到ASP.NET吗? Eg simple *.mvc or more complicated using regex like /\\d+[.]mvc/i ? 例如简单的*.mvc或使用/\\d+[.]mvc/i这样的正则表达式更复杂?

I have next lines under system.webServer in my web.config 我的web.config system.webServer下有下一行

<modules runAllManagedModulesForAllRequests="true">
  <remove name="UrlRoutingModule" />
  <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</modules>
<handlers>
  <remove name="UrlRoutingHandler" />
  <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpNotFoundHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</handlers>

Your question is not very clear, but let me try an answer. 您的问题不是很清楚,但让我尝试一个答案。

URLs are mapped to handlers by IIS when the request is initially received. 最初收到请求时,IIS将URL映射到处理程序。 There are managed handlers (asp.net) and unmanaged handlers (IIS built-in). 有托管处理程序(asp.net)和非托管处理程序(IIS内置)。 A request with a managed handler will enter ASP.NET and be processed by the various managed modules in the pipeline. 具有托管处理程序的请求将进入ASP.NET,并由管道中的各种托管模块处理。 A request with an unmanaged handler, also, won't be processed by managed code until you set runAllManagedModulesForAllRequests=”true” or removing the " managedHandler " preCondition for the UrlRoutingModule . 具有非托管处理程序的请求也不会由托管代码处理,直到您将runAllManagedModulesForAllRequests=”true”或为UrlRoutingModule删除了“ managedHandler ”前置条件。

UrlRoutingModule inspects the requests and will change the handler mapping according to the route table. UrlRoutingModule检查请求,并将根据路由表更改处理程序映射。 If it doesn't change the handler mapping, then the original handler mapping will be used--the one set by IIS. 如果不更改处理程序映射,则将使用原始处理程序映射-由IIS设置的一个。

Since asp.net 4.0, the is also a new generic "*" handler for extensionless Url. 从asp.net 4.0开始,对于无扩展网址,它也是一个新的通用“ *”处理程序。

There is sometimes is big misunderstood between rewriting & routing. 有时在重写和路由之间存在很大的误解。 URL rewriting is used to manipulate URL paths before the request is handled by the Web server. URL重写用于在Web服务器处理请求之前操纵URL路径。 (rewriting module does not know which handler will eventually process the request, request handler might not know that the URL has been rewritten. On the other side, ASP.NET routing is used to dispatch a request to a handler based on the requested URL path. It's an advanced handler-mapping mechanism. (重写模块不知道哪个处理程序最终将处理该请求,请求处理程序可能不知道URL已被重写。另一方面,ASP.NET路由用于根据请求的URL路径将请求分派给处理程序这是一种高级的处理程序映射机制。

Here is a sample of managed handlers of my root web.config 这是我的根web.config的托管处理程序的示例

<httpHandlers>
            <add path="trace.axd" verb="*" type="System.Web.Handlers.TraceHandler" validate="True" />
            <add path="*.aspx" verb="*" type="System.Web.UI.PageHandlerFactory" validate="True" />
            <add path="*.ashx" verb="*" type="System.Web.UI.SimpleHandlerFactory" validate="True" />
            <add path="*.asmx" verb="*" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="False" />
           ...
            <add path="*.config" verb="*" type="System.Web.HttpForbiddenHandler" validate="True" />
            <add path="*.cs" verb="*" type="System.Web.HttpForbiddenHandler" validate="True" />
            <add path="*.csproj" verb="*" type="System.Web.HttpForbiddenHandler" validate="True" />
            <add path="*.vb" verb="*" type="System.Web.HttpForbiddenHandler" validate="True" />
            ...
            <add path="*" verb="GET,HEAD,POST" type="System.Web.DefaultHttpHandler" validate="True" />
            <add path="*" verb="*" type="System.Web.HttpMethodNotAllowedHandler" validate="True" />
        </httpHandlers>

As you can see, this config maps to System.Web.UI.PageHandlerFactory but maps *.cs to System.Web.HttpForbiddenHandler (don't want to expose *.cs files). 如您所见,此配置映射到System.Web.UI.PageHandlerFactory但将* .cs映射到System.Web.HttpForbiddenHandler (不想公开* .cs文件)。

As for most of the things, there are many ways to solve your problem : clearing all handlers, use routing, ... 至于大多数事情,有很多方法可以解决您的问题:清除所有处理程序,使用路由,...

Hope this is more clear. 希望这更加清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM