The execution order of the IIS7 HttpModule and ISAPI filter

I have a website using ISAPI Rewrite , as well as a custom HttpModule that redirects and rewrites Url.

In IIS 6, everything worked fine: the ISAPI rewrite filter starts first, followed by the HttpModule. In IIS 7 (Integrated Mode), the order is now reversed, which creates a problem.

My problem in particular is that the HttpModule has a condition in which it will issue a rewrite of Url using context.RewritePath . It will explicitly add "index.aspx" to the path if the document was not provided, so the request for /test/ will be rewritten to /test/index.aspx .

At some point after the path is rewritten, the ISAPI filter is intercepted. We have a rule opposite to the module: a request to /test/index.aspx receives a 301 redirect to /test/ . So we have an infinite loop.

How is the execution order of the HttpModules and ISAPI filters in IIS 7 determined? Can I reorder? I found this question , but that did not help. I am not a master of IIS 7, but to some extent I understand that ISAPI modules and filters work "together." Unfortunately, they are still managed differently, and I cannot figure out how to get someone to work in front of another. Help!

Note. Suppose I cannot modify existing code. It worked in IIS 6. I just want to know if there is a way to make it work in IIS 7 integrated mode.

+6
iis-7 isapi
source share
2 answers

I also had a similar problem when I thought that ISAPI rewriting is done first, but apparently not the way everything works with IIS7

I found this thread that points

In integrated mode, events for the built-in module, isapi and .net are called mixed together

eg. if it is BeginRequest, then the first module will be first, then isapi, then .net code. After that, everything will be repeated for AuthenticateRequest ...

Some time ago, it was like this: isapi processed all the events, and only after that .net was called. This is probably what you suggested.

http://www.helicontech.com/forum/18447-ISAPI_RW3_Lite_on_IIS_7x_Integrated_mode.html

Hope this helps

+3
source

Have a look at the following article that explains the IIS 7 pipeline . Unable to reorder the pipeline. Not sure if this is an option or not, but you could replace ISAPI Rewrite using the IIS re-url module . This may allow your application to work in integrated pipeline mode, otherwise you may need to switch the application pool to run in classic mode.

0
source

All Articles