net下多个应用之间的web.config冲突的解决办法(禁止继承)

转自:http://blog.163.com/zhslls/blog/static/4745614520107200118992/

net下多个应用之间的web.config冲突的解决办法(禁止继承)

2010-08-20 00:01:18| 分类: DOTNET | 标签:技术 |字号 订阅

网站子目录下存在多个WEB.CONFIG文件,其中连接串名称相同,起冲突。

<location path="." allowOverride="true" inheritInChildApplications="false">
<connectionStrings>
<add name="ddConnectionString" connectionString="Data Source=127.0.0.1;Initial Catalog=test;User

ID=sa;Password=bb" />

</connectionStrings>
</location>

网络中的资料:

禁止虚拟目录继承根目录下webconfig中的有些配置 web.config的继承禁止方法
网站用了url重写,但是不想让站点下面的几个子站受到Url重写的影响,确又不希望更改和重新配置这些子站(虚拟目录创建),
受影响的有两个方面:
一.在子站下需要加入对应的url重写组件到子站的bin目录下
二.子站下的url地址,受根目录url重写配置的影响
目前只能把url重写的.dll复制子站下的bin目录,然后在对应的子站的web.config里添加上
<system.web>
<!--add-->
<httpModules>
<clear/>
</httpModules>
<!--add-->
这种方式来处理,还是有很大的缺点,要复制相关的.dll
当然希望能够实现,不用修改子站点的任何信息,下面介绍另一种方法:
1.如果是asp.net1.1的程序,那么把IIS配置的asp.net 改成2.0的,(1.1可以在.net2.0下面运行,不影响原来的程序正常运行)
2.在根目录下面的web.config加上
<location path=”.” allowOverride=”false” inheritInChildApplications=”false”>
........
</location>
path 不用说指定的是一个目录
allowOverride 指是否可以将这个重写
inheritInChildApplications 指是否被子级应用程序继承
说明:因为inheritInChildApplications 这个属性,在asp.net1.1里是没有的 所以1.就是为当前修改的配置而设
具体运用实例:根目录下的web.config:
例1:
<location path=”.” allowOverride=”false” inheritInChildApplications=”false”>
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
</httpHandlers>
</system.web>
</location>
例2:
<location path="." allowOverride="true" inheritInChildApplications="false">
<system.web>
<httpModules>
<add name="UrlRewriteModule"
type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</httpModules>
</system.web>
</location>
说明:上面的配置就不会对虚拟目录中的web.config继承主目录中web.config的问题了,(注:IIS一定要.net2.0的配置才行,网上很多资料没有注明这一点)
总结:
1.站点要.net2.0的环境
2.根目录下的web.config 用<location path="." allowOverride="true" inheritInChildApplications="false"></location>来限止web.config的一些继承

原文地址:https://www.cnblogs.com/SharkXu/p/WebConfigConflict.html