Web.config httpModules remove if exists?

S

Samuel R. Neff

We have a problem with Web.config inheritance in two of our
applications. We have an old app which is poorly written and must be
in the root of the server. We have a newer app which runs from a
virtual directory. The apps are not related.

Old app web.config has:

<httpModules>
<add name="a" type="foo.a, foo" />
<add name="b" type="bar.b, bar" />
</httpModules>

So in the new app we get errors that it can't find assemblies "foo"
and "bar'. If we add this to the new app's web.config:

<httpModules>
<remove name="a" />
<remove name="b" />
</httpModules>

it works only on developer machines that have both apps--fails
otherwise (error removing module that doesn't exist).

The only solution we can think of is to create a fake app which has
empty modules with the same names as the old app's modules and install
that on the developer machines that only work on the new app. This
shoud work but is really ugly.

Are there any other options? (fixing the old app is not an option
right now due to resources and the time it would take to fix it and
it's only a problem in development, not testing or production).

Thanks,

Sam
 
R

Rick Strahl [MVP]

Hi Sam,

I've dealt with this sort of thing a few times as well. To be honest the
<remove> modules should do the trick though unless you're not removing in
the right place - the problem may show up in any intermediary Virtuals as
well...

One thing that you can look at is loading the modules via code so they don't
show up in the root config file. It would require touching your 1.1 app, but
it's going to be very simple and can be done in global.asax if necessary...

It's easy to do - just manually attach the module in the Init() method of
your HttpApplication instance (ie. global.asax/cs):

public class Global : System.Web.HttpApplication
{
public static xrnsToashxMappingModule Module = new
xrnsToashxMappingModule();


public override void Init()
{
base.Init();

Module.Init(this);
}

}


Hope this helps,

+++ Rick ---
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top