您的位置:首页 > 编程语言 > ASP

在Web.Config文件中使用configSource,避免动态修改web.config导致asp.net重启(另添加一个Config文件用于管理用户数据)

2010-09-13 10:40 1141 查看

我们都知道,在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文件,就不会导致重启了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐