Dynamically Loading Custom Http Modules

Dynamically Loading Custom Http Modules

am 04.04.2008 23:08:54 von Peter Schwartz

Here is what I plan to do (the question follows the description):

My intent is to have a custom HTTP module dynamically determine which
classes should handle various pipeline events. We'll call this the "loader
module". The loader module then (1) loads the assemblies that house the
other classes, instantiating the requisite object; then (2) wires up the
requisite pipeline event to the corresponding event handling method of the
class instantiated from the dynamically loaded assembly.

The idea here is that I can, for example, have a few different classes (each
in its own assembly) that can handle specific HTTP pipeline events (like
BeginRequest or AuthenticateRequest) - and then have one of those classes
process that event during all future requests. This would allow me to have,
for example, multiple custom authentication mechanisms - each implemented in
its own class and assembly, one of which is then plugged into the
application by my custom HTTP module.

My question:
Will this even work? FWIW: I know how to dynamically load assemblies and
instantiate classes from them. I'm just not understanding the mechanism in
ASP.NET that would call my custom HTTP module (the "loader module") - which
needs to be called only once; yet call the dynamically loaded Request
processing module(s) for every single request (to handle, for example, the
AuthenticateRequest event).

Thanks.