开发者

Detect mapped virtual directories from an ihttpmodule in a c# .net application

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 subsequ开发者_如何学编程ent requests...


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)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜