ASP.NET - Web.Config - Using the tag with web.config can be helpful.

本文介绍如何利用web.config文件中的<remove/>标签来移除父级web.config文件中不需要的功能定义,避免这些定义干扰或破坏应用程序。通过具体示例展示了如何移除特定的CommerceServer组件及.NET组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 applicationthen 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 enableyou 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 enableyou 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 enableyou 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值