zoukankan      html  css  js  c++  java
  • 转载自http://blog.sina.com.cn/s/blog_551dd6690100nfk4.html,在Web.Config文件中使用configSource

    在Web.Config文件中使用configSource

    我们都知道,在asp.net中修改了配置文件web.config后,会导致应用程序重启,所有会话(session)丢失。然而,应用程序的配置信息放在配置文件里是最佳选择,在后台修改了配置后导致所有会话丢失是非常不爽的事情,这个时候可将配置文件中经常需要改变的参数配置节放到外面来,例如appSetting节。

    一、原来的web.config文件:

    <?xml version="1.0" encoding="utf-8"?>  <configuration>     <appSettings>      <add key="CacheTimeInfo" value="30" />      <add key="CacheTimeNews" value="10" />      <add key="CacheTimeProduct" value="60" />      <add key="CacheTimeTrade" value="5" />      <add key="SiteName" value="中国叉叉网"/>      <add key="SiteDomain" value="chinaxx.com"/>     </appSettings>    <connectionStrings/>    <system.web>      <compilation debug="false">      </compilation>      <authentication mode="Windows" />    </system.web>  </configuration>

    二(1/2)、现在的web.config文件

    <?xml version="1.0" encoding="utf-8"?>  <configuration>     <appSettings configSource="Config\AppSettings.config" /> <connectionStrings/>    <system.web>      <compilation debug="false">      </compilation>      <authentication mode="Windows" />    </system.web>  </configuration>

    二(2/2)、现在的Config目录下的AppSettings.config文件

    <?xml version="1.0" encoding="utf-8"?> <appSettings> <add key="CacheTimeInfo" value="30" /> <add key="CacheTimeNews" value="10" /> <add key="CacheTimeProduct" value="60" /> <add key="CacheTimeTrade" value="5" /> <add key="SiteName" value="中国叉叉网"/> <add key="SiteDomain" value="chinaxx.com"/> </appSettings>

    这样在程序中修改Config\AppSettings.config文件,就不会导致重启了。

    在站点的默认 Web.Config 文件中使用:

    在 .NET Framework 2.0 版中,现在可以在一个单独文件包括所有支持 configSource 属性的配置元素的配置设置。但是,当使用 configSource 属性时,由于没有元素设置的合并,因此您必须将整个节移动到单独文件。使用 configSource 属性时,对 Web.config 文件有一次写入操作。这会导致应用程序重新启动,但是随后对该节的更新会直接写入单独文件,而不会导致后面的应用程序重新启动。

    只能包含一次configSource;

    在网站运行时,如果修改 Web.Config 文件会引起站点的重启,而修改 My.Config 文件则不会,同时也提高了配置文件的可读性

    注意,configSouce中的文件路径只能为相对物理路径,也就是只能为反斜杠(\),不能用斜杠(/)。

  • 相关阅读:
    spring相关记录
    xshell不能连接VM中的ubuntu
    MySQL 获得当前日期时间(以及时间的转换)
    struts2 action获取ajax提交数据中文乱码问题
    Write operations are not allowed in read-only mode (FlushMode.NEVER/
    在Action中以Struts2的方式输出JSON数据
    javascript 对象数组排序
    期待2015
    Mysql 导出数据库和指定表中的数据
    Ajax跨域问题
  • 原文地址:https://www.cnblogs.com/wangzhen/p/2857319.html
Copyright © 2011-2022 走看看