Weird Issue with HttpModules

K

Karch

I have an assembly which contains 2 HttpModule class that inherit from a
base class. The base class simply provides some common methods - nothing
special. The strange thing is that, even though I only specify one or the
other modules in the httpModules section, it seems that both constructors
are called. What is going on here? How do I force it to only load the
HttpModule that is indicated like so:

If I want MyModule1 to be the "active" module, I specify this in the
web.config:

<httpModules>
<add type="MyAssembly.MyModule1, MyAssembly" name="MyModule1" />
</httpModules>

If I want MyModule2 to be the "active" module, I specify this in the
web.config:

<httpModules>
<add type="MyAssembly.MyModule2, MyAssembly" name="MyModule2" />
</httpModules>

What am I doing wrong? I keep getting runtime errors from the MyModule1
constructor when I have specified the MyModule2 module (the contructor for
MyModule2 executes as well, by the way). I am using .NET 2.0 Framework.

Thanks,
K
 
M

Michael Nemtsev [MVP]

Hello Karch,

Not completely sure, but such behaviour shows that your 2 modules are loaded
when your common base code is initialized, because your modules are located
in the same dll
Why not to put your modules in different dlls? because now they serves as
the single module

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


K> I have an assembly which contains 2 HttpModule class that inherit
K> from a base class. The base class simply provides some common methods
K> - nothing special. The strange thing is that, even though I only
K> specify one or the other modules in the httpModules section, it seems
K> that both constructors are called. What is going on here? How do I
K> force it to only load the HttpModule that is indicated like so:
K>
K> If I want MyModule1 to be the "active" module, I specify this in the
K> web.config:
K>
K> <httpModules>
K> <add type="MyAssembly.MyModule1, MyAssembly" name="MyModule1"
K> />
K> </httpModules>
K> If I want MyModule2 to be the "active" module, I specify this in the
K> web.config:
K>
K> <httpModules>
K> <add type="MyAssembly.MyModule2, MyAssembly" name="MyModule2"
K> />
K> </httpModules>
K> What am I doing wrong? I keep getting runtime errors from the
K> MyModule1 constructor when I have specified the MyModule2 module (the
K> contructor for MyModule2 executes as well, by the way). I am using
K> .NET 2.0 Framework.
K>
K> Thanks,
K>
 
K

Karch

There is a business requirement that they be in the same assembly, and I
don't really see anything unreasonable about that. For exampe, assume I have
20 different modules and I want to deploy only 1 assembly to target
machines. Same thing here.

But, anyway, that's not the answer I was hoping for. The base code being
initialized should have nothing to do with it if I am specifying only one of
them. By the way, the base class, MyBaseModule implements IHttpModule and
then MyModule1 and MyModule2 inherit from MyBaseModule. So:

MyBaseModule : IHttpModule
MyModule1 : MyBaseModule
MyModule2 : MyBaseModule

Nevertheless, when I specify to load MyModule2, I can't see any reason that
MyModule1 would also be loaded.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top