码迷,mamicode.com
首页 > Web开发 > 详细

配置子目录Web.config使其消除继承,iis7.0设置路由

时间:2015-06-16 10:33:51      阅读:404      评论:0      收藏:0      [点我收藏+]

标签:

iis7.0设置路由 ,url转向,伪静态

<system.webServer>  
    <modules runAllManagedModulesForAllRequests="true" />  
    </system.webServer>

配置子目录Web.config使其消除继承  

不用修改根目录的Web.config文件,而是修改子目录的Web.config。假设根目录的Web.config设置了一个名为 BlogEngine的连接字符串,要在子目录使用另一个名字为BlogEngine的连接字符串,就需要先清除已有的连接字符串(根目录继承下来的 connectionString设置),清除所有的配置,可以用clear语法,清除指定名称的配置,可以用remove语法,如下

<--根目录的Web.config-->
<connectionStrings>
  <add name="BlogEngine" connectionString="Data Source=localhost\SQLEXPRESS; Initial Catalog=BlogEngine1; User ID=xxx; Password=xxx" providerName="System.Data.SqlClient"/>
</connectionStrings>
<--子目录的Web.config(clear方法)-->
<connectionStrings>
  <clear/>
  <add name="BlogEngine" connectionString="Data Source=localhost\SQLEXPRESS; Initial Catalog=BlogEngine2; User ID=xxx; Password=xxx" providerName="System.Data.SqlClient"/>
</connectionStrings>
<--子目录的Web.config(remove方法)-->
<connectionStrings>
  <remove name="BlogEngine"/>
  <add name="BlogEngine" connectionString="Data Source=localhost\SQLEXPRESS; Initial Catalog=BlogEngine2; User ID=xxx; Password=xxx" providerName="System.Data.SqlClient"/>
</connectionStrings>

这里只是用connectionString为例,使用时完全可以应用在所有可以配置的节点上,任何配置节点都可以用clear和remove节点 将继承来的配置先清除掉,然后再add新的配置。此方法灵活性更强,同时可以保留根目录Web.config中的部分共同配置(而无需全部重新设定)。

 

配置子目录Web.config使其消除继承,iis7.0设置路由

标签:

原文地址:http://www.cnblogs.com/w158357686/p/4579954.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!