zoukankan      html  css  js  c++  java
  • 在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文件,就不会导致重启了。

  • 相关阅读:
    NFS
    Linux ISO镜像挂载
    Python3.6 提示 ModuleNotFoundError: No module named '_ssl' 模块问题
    mysql 5.7 ERROR 1054(42S22) Unknown column 'password' in ‘field list’ 报错
    Redis + keepalived 高可用行配置检测脚本
    Linux 文件大小查找排序
    查看 Centos 7 的MAC 地址
    Discuz 论坛 (LAMP环境)
    SVN
    systemctl
  • 原文地址:https://www.cnblogs.com/scgw/p/1936944.html
Copyright © 2011-2022 走看看