开发者

IIS7 HttpModule and ISAPI Filter execution order

开发者 https://www.devze.com 2023-02-17 19:12 出处:网络
I have a site using ISAPI Rewrite as well as a custom HttpModule that both do Url redirects and rewrites.

I have a site using ISAPI Rewrite as well as a custom HttpModule that both do Url redirects and rewrites.

In IIS 6, everything worked fine: The ISAPI Rewrite filter would run first, followed by the HttpModule. In IIS 7 (Integrated mode) the order is now the reverse, which poses a problem.

My problem, specifically, is that the HttpModule has a condition where it will issue a Url rewrite using context.RewritePath. It will explicitly add "index.aspx" to the path if no document was provided, so a request to /test/ gets rewritten to /test/index.aspx.

At some point after the path is rewritten, the ISAPI Rewrite filter executes. We've got a rule that does the opposite of the module: a request to /test/index.aspx gets 301-redire开发者_C百科cted to /test/. Thus, we have an endless loop.

How is the execution order of HttpModules and ISAPI Filters determined in IIS 7? Can the order be changed? I found this question, but it didn't really help. I'm not a master of IIS 7, but I do understand to some extent that modules and ISAPI filters run "together". Unfortunately, they are still administered differently and I can't figure out how to force one to run before the other. Help!

Note: let's assume I cannot change the existing code. It worked in IIS 6. I just want to know if there's a way to make it work in IIS 7 Integrated mode.


I've also had a similar problem where I thought that ISAPI rewrites get executed first, but apparently that's not how things work with IIS7

I found this thread that states

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

e.g. if it's a BeginRequest then the native module is the first to come, then isapi, then .net code. After that everything will repeat for AuthenticateRequest...

Some time ago it used to be like this: isapi has processed all events, and only after that .net was invoked. This is probably what you've assumed.

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

Hopefully it helps


Have a look at the following article which explains the IIS 7 pipeline. The order of the pipeline cannot be changed. Not sure if this is an option or not, but you could potentially replace the ISAPI Rewrite with the IIS URL Rewrite module. This may allow your application to run in the integrated pipeline mode, otherwise, you may need to switch your app pool to run in classic mode.

0

精彩评论

暂无评论...
验证码 换一张
取 消