Mathew Nolton Blog

Software dementia unleashed...

Using the <remove> tag with web.config can be helpful.

Most people use the web.config file to define features or pieces of functionality to be used by their application. You may or may not know it, but there is a feature of the web.config file that enables you to remove definitions defined by a parent web.config file. This is especially important when an application (either rightly or wrongly) places a web.config file in the root web directory or your parent directory that adds functionality or puts a constraint on all child directories that you do not want or that will break your application.

The web.config file has a heirarchy of sorts. All applications pick up their defaults from the machine.config file. Your application then uses any parent directory web.config file before using it's own web.config file. This means that if you are a couple levels deep and your parent directories have web.config files defined, you will pick up your defaults first from them before your own is processed.

This heirarchy is helpful when carefully planned; however, if a parent directory makes assumptions that are not valid or the person deploying the application does not consider all avenues, it presents a problem. I ran across this situation when a commerce server implementation added some .net functionality and placed a web.config file in the root web directory. When I deployed my .net application I inherited all of its defaults....which would have broken my application. To get around this, I used the <remove/> tag of the web.config. For example, the CommerceServer implementation defined a number of commerce server pieces that I did not want...nor could my application handle:

<configuration>
   <configSections>
      <remove name="CommerceServer/application"/>               <---- Most sections enable you to remove
      <remove name="CommerceServer/authentication"/>
      <remove name="CommerceServer/pipelines"/>
      <remove name="CommerceServer/caches"/>
      <remove name="CommerceServer/messageManager"/>
      <remove name="CommerceServer/catalog"/>
      <remove name="CommerceServer/orders"/>
      <remove name="CommerceServer/profiles"/>
      <remove name="CommerceServer/contentSelection"/>
      <remove name="CommerceServer/commerceEvent"/>
   </configSections>
   <system.web>
      <httpModules>
         <remove name="CommerceApplication"/>                        <---- Most sections enable you to remove
         <remove name="CommerceAuthentication"/>
         <remove name="CommerceOrder"/>
         <remove name="CommerceProfile"/>
         <remove name="CommerceExpressionEvaluator"/>
         <remove name="CommerceCache"/>
         <remove name="CommerceContentSelection"/>
         <remove name="CommerceCatalogModule"/>
   </httpModules>
............................
   <compilation defaultLanguage="c#" debug="false">
      <assemblies>
         <remove assembly="Microsoft.CommerceServer.Runtime, Version=4.5.2002.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>           <---- Most sections enable you to remove
      </assemblies>
   </compilation>
  <customErrors mode="RemoteOnly" />
............................
 </system.web>
</configuration>

Be carefule using the <clear/> tag, it will clear out everything for that section including defaults from the machine.config file....Typically, you do not want to do this.

Overall, if you have a parent application or parent web directory that isn't well-behaved, you do have options in working around this problem.

-Mathew C. Nolton

Posted: Jan 10 2005, 11:35 AM by MatiasN | with 6 comment(s)
Filed under:

Comments

jrblack10 said:

I have been trying to use this <Remove /> tag, but I can't seem to figure it out.  Is this feature also available in .Net 1.1?

My problem is that I have a .Net 2 app in the web root and virtual directories (to Reporting Services) that are .Net 1.1.  So the v1.1 app blows up on all kinds of statements in the web.config of the parent web.  I am not talking about features I don't want to implement in the sub web, but features or settings that don't exist or not allowed in v1.1.

ERROR:

Parser Error Message: Child nodes are not allowed.

<system.web>

   <pages>

       <controls> <- THIS IS REPORTED AS THE ERROR

If you can help clear any of this up, that would be great!

# May 16, 2007 9:35 AM

Siraj said:

Got what i wanted! .. thankx

# July 1, 2007 4:21 PM

HOw said:

I just simply want to remove the "Sign in" link.. at the top of my Ad Authenticated Moss 2007 site... how do i do this?

my e-mail i Jswann@voa.org can you please e-mail me our responce

# April 30, 2008 12:04 AM

koy chamnap said:

could you define more about "<remove> tag" fomular and sort example of remove connectionstring and replace with another connectionstring.

# October 2, 2008 1:00 PM

Twitter Mirror said:

Using the &lt;remove&gt; tag with web.config can be helpful. http://weblogs. asp.net /mnolton/archive

# March 24, 2010 2:15 AM

Twitter Trackbacks for Using the <remove> tag with web.config can be helpful. - Mathew Nolton Blog [asp.net] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Using the &lt;remove&gt; tag with web.config can be helpful. - Mathew Nolton Blog         [asp.net]        on Topsy.com

# March 25, 2010 3:47 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)