IIS URL Rewrite - one of known issues with the rewriteBeforeCache feature
I ran into IIS worker process (w3wp.exe) crash issue under specific conditions:
- If IIS apppool is running in the Classic mode
- ExtensionlessUrlHandler is configured
- IIS Url Rewrite outbound rule is configured with enabling with setting rewriteBeforeCache="true".
After investigating the issue, I found one work-around way to avoid the crash issue and hoped to share it here.
In this case, the IIS Url Rewrite module tried to use the HttpContext object which was already deleted because the the object was created earlier while handling the extensionless URL, which is supposed to be handled with creating a child request.
The child request is created by the ExtensionlessUrlHandler module in order to complete send the response to the user and the IIS Url Rewrite module was trying to use the context after that, which is a bug of IIS URL Rewrite modle. .
Because the crash issue happens under those errorneous conditions, there are various workaround ways like this:
- If we use Integrated Mode instead of the Classic mode, the crash issue won't happen because the Url Rewrite module uses a different code path.
- Or, if we remove the ExtensionlessUrlHandler modules, the AV issue is also fixed even though the classic mode is being used. This is because the ExtensionlessUrlHandler module does not complete sending response earlier.
- Finally, if we disable the rewriteBeforeCache feature, the issue can be solved as well even though we keep using the Classic mode and the ExtensionlessUrlHandler module.
NOTE
- If you decided to keep rewriteBeforeCache enabled, URL Rewrite's outbound rule won't be applied for the extensionless requests because the ExtensionlUrlHandler sends the response ealier than Url Rewrite module.
If you want to apply the outbound URL Rewrite rule to the extensionless requests as well, you should disable the rewriteBeforeCache feature. - If rewriteBeforeCache is disabled, there can be some performance penalty. So, you should make sure optimizing the Url Rewrite outboud rules if you see any performance issue after the change.
In my opinion, disabling the rewriteBeforeCache feature is the simplest workaround way to avoid the crash issue until the bug of IIS Url Rewrite moudle is fixed.
So, here I'd like to share the way about how to disable the rewriteBeforeCache feature.
Considering the fact that the default attribute value of the rewriteBeforeCache is "false", you can disable the feature with changing the IIS Url Rewrite ouboundRule section as the following:
<rewrite> <outboundRules> ... |
- Or -
<rewrite> <outboundRules rewriteBeforeCache="false"> ... |