views:

126

answers:

1

I have a .net website which contains an IHttpModule I wrote to do certain tasks (authorisation etc). But within the website there are a number of virtual directories that are mapped to third party applications which unfortunately I can't change or move (e.g. community server forums, adxstudio cms and others).

I am looking for a way to prevent my IHttpModule from running when requests are made for the contents of those virtual directories. Is this possible?

[Edit - added the following]

I have been experimenting with adding <remove name="X"/> inside the <httpModules> node in the Web.config files in the virtual directory applications but it doesn't seem to be working out. It probably isn't a great solution either because the third party applications can be updated so I don't want to require changes to their code/ configuration.

I also tried adding a <location path="." inheritInChildApplications="false"> around my <system.web> node in the parent Web.config but that also didn't seem to work.

[Edit again - added more]

The reason is doesn't work is because the IHttpModule's Init event is only fired once per application lifecycle (rather than per request as I had assumed). Since I add a bunch of event listeners in the init event these are still fired on subsequent requests...

+2  A: 

If you have a list of these directories and their virtual paths, you can build a lookup of them.

For every HttpRequest that triggers your module, you can check for the virtual path to see if it belongs to any of the path in the lookup. If yes, you can then do nothing or exit your module's code.

PS: For performance issue, you probably want to store the lookup in the application state (e.g. hashmap etc)

o.k.w
Thanks for the solution - I guess this is the way I'll have to go. It seems like there should be something more "built in" and efficient than coding my own logic. I've updated the question above with some comments on other approaches I've taken - do you think there could be anything along those lines that might help?
vitch
Marking as the answer as this is what I ended up doing. Still seems like there should be a cleaner solution but if this is the way it should be done then c'est la vie!
vitch