配置子目录Web.config使其消除继承,iis7.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中的部分共同配置(而无需全部重新设定)。

 

posted @ 2015-06-16 09:46  w158357686  阅读(811)  评论(0编辑  收藏  举报