• 在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文件,就不会导致重启了。

  • 相关阅读:
    react.js+axios跨域
    O2O项目之一 环境搭配
    跟scss相关的两个包
    [nodemon] app crashed
    解决node.js链接数据库时出现的报错 --- client does not support authentication
    在Xshell 运行angular 项目时,找不到node-sass模块,安装node-sass模块时,又出现权限问题
    ajax请求数据时,get和post的区别
    web前端如何性能优化提高加载速度
    js数组去重
    前端跨域
  • 原文地址:https://www.cnblogs.com/scgw/p/1936944.html
Copyright © 2020-2023  润新知