HttpModule URL rewriting using IIS6 with no extens

2019-05-10 19:52发布

问题:

We are using the Intelligencia URLRewriting module for asp.net with version 2.0 of the framework and IIS6. Our URLs typically have no extension.

I understand that IIS6 cannot really deal with this situation without a blanket wildcard (which causes other problems).

However, it works! Sometimes. At other times (e.g. on one dev's machine, and on my machine when I point a different virtual directory at the app) it doesn't. By "it doesn't work" I mean the configured HttpModules never even get hit.

Can anyone explain this?

Thanks.

回答1:

So it turns out what was happening was the following:

  • request comes in to (say) http://website/products/productid
  • IIS can't find this hence we get a 404
  • by chance we have a custom error page set up in IIS for 404s
  • this error page sticks the referring URL on the end of the 404 error.aspx page
  • so we get a redirect coming into asp.net along the lines of:

    http://website/error.aspx?404;http://website/products/productid

  • our URLRewriting regexes were now set up in such a way that they discarded the error.aspx bit and dealt with http://website/products/productid as if it were the actual URL

  • so asp.net renders http://website/product.aspx?id=productid as requested!

I guess this could prove to be a useful kludge for someone, but we're moving to an isapi filter. One heads-up is that this will by default lead to a tight loop of redirects!



回答2:

If you run a site using the Visual Studio development web server all requests will be handled by asp.net so your HttpModule will run.

On IIS6 this should not happen unless it is set up to forward the requests to asp.net.



回答3:

Are you sure that when "it works" you aren't running under the Cassini development web server included in VS.NET ? Because extensionless wildcards do work under Cassini, which can be very confusing to say the least.



回答4:

If you are using an IIS6 with ASP.net 4.0, you must specify and register the modules like this:

<system.web>
<httpModules>
      <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>

not

<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
</modules>