简体   繁体   中英

IIS 7.5 integrated pipeline filter requests for asp.net

Can I somehow send to ASP.NET part only request that matches some pattern? Eg simple *.mvc or more complicated using regex like /\\d+[.]mvc/i ?

I have next lines under system.webServer in my web.config

<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. There are managed handlers (asp.net) and unmanaged handlers (IIS built-in). A request with a managed handler will enter ASP.NET and be processed by the various managed modules in the pipeline. 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 .

UrlRoutingModule inspects the requests and will change the handler mapping according to the route table. If it doesn't change the handler mapping, then the original handler mapping will be used--the one set by IIS.

Since asp.net 4.0, the is also a new generic "*" handler for extensionless Url.

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. (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.

Here is a sample of managed handlers of my root 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).

As for most of the things, there are many ways to solve your problem : clearing all handlers, use routing, ...

Hope this is more clear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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