web.config里面使用configSource
在asp.net中如果修改了配置文件web.config以后,会导致应用程序重启,所有回话(session)丢失掉,在 .NET Framework 2.0 以后的版本中,可以在一个单独文件中包括所有支持 configSource 属性的配置元素的配置。这样既不用重启应用程序,也方面管理,避免把所有的配置都放在web.config一个文件里使页面看起来比较乱。例如appSetting、connectionStrings节点。
例子如下:
注意,configSouce中的文件路径只能为相对物理路径,也就是只能为反斜杠(\),不能用斜杠(/)。
首先是web.config文件:
<configuration>
<!-- appSettings网站信息配置-->
<appSettings configSource="config\appSettings.config" />
<connectionStrings configSource="config\connectionStrings.config"/>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpHandlers configSource="config\httpHandlers.config" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
<pages configSource="config\pages.config" />
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership> <profile>
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
</providers>
</profile> <roleManager enabled="false">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager> </system.web> <system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
下面是两个单独的配置文件:
1、appSettings.config
<?xml version="1.0" encoding="utf-8"?> <appSettings>
<!-- Base parameter -->
<add key="SiteResource" value="http://s.baidu.com"/>
<add key="SiteUrl" value="http://www.baidu.com" />
<add key="SiteName" value="www.baidu.com" />
<add key="SiteKeyword" value="baidu"/>
<add key="AllFreeShipping" value="false"/>
<add key="ReduceCashBegin" value="2013-9-10 16:00:00"/>
<add key="ReduceCashEnd" value="2013-9-16 16:00:00"/>
<add key="ReduceCashRule" value="500:30|400:25|300:20|200:15|100:10"/>
</appSettings>
2、connectionStrings.config
<?xml version="1.0"?>
<connectionStrings>
<add name="connectionStrings"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
读取的时候的方式不变,跟以前一样,这里就写两个:
/// <summary>
/// CSS、JS引用地址
/// </summary>
public static string SiteResource
{
get
{
return ConfigurationManager.AppSettings["SiteResource"] as string;
}
}
/// <summary>
/// 减现规则
/// </summary>
public static Dictionary<decimal, decimal> ReduceCashRule
{
get
{
string val = ConfigurationManager.AppSettings["ReduceCashRule"] as string;
string[] rule = val.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
Dictionary<decimal, decimal> dic = new Dictionary<decimal, decimal>();
foreach (string item in rule)
{
string[] arr = item.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
dic.Add(decimal.Parse(arr[]), decimal.Parse(arr[]));
}
return dic;
}
}
PS:中分看鼻子,齐刘海看脸型,斜刘海看气质,无刘海看五官。。。我适合蒙面!!!!
web.config里面使用configSource的更多相关文章
- 在web.config里使用configSource分隔各类配置
转:http://www.yongfa365.com/Item/using-configSource-Split-Configs.html 大型项目中,可能有多个Service,也就是会有一堆配置,而 ...
- web.config中的configSource
在大型项目中,可能存在第三方类库的配置如:log4.net,AOP框架Unity,WCF等,或是自定义的配置,造成web.config内容过多,不易维护,影响Config初始化. 这时我们可以使用co ...
- Web.Config引入配置ConfigSource
1.配置文件要和Config文件通一个项目 2.注意路径的写法 3.appSettings和connectionStrings等都可以设置configSource 4.这样发布到不同的环境的时候,改动 ...
- 通过configSource提高web.config配置灵活性
很多时候我们会有这样的情况,开发环境和测试环境中的配置文件是不一样的,最明显的就是数据库连接串,这样,每次我们发布一个测试版本,都要手动去修改一下配置文件,是不是很麻烦的说.其实利用web.confi ...
- ASP.Net Web.config 中引用外部config文件
1. 前提准备: Web.config file: <?xml version="1.0" encoding="utf-8"?><config ...
- ASP.NET MVC系列:web.config中ConnectionString aspnet_iis加密与AppSettings独立文件
1. web.config中ConnectionString aspnet_iis加密 web.config路径:E:\Projects\Libing.Web\web.config <conne ...
- C# 灵活切换开发/测试/生成环境web.config
web.config <configuration> <connectionStrings configSource="config\Sit.db.config" ...
- Web.Config文件中使用configSource
我们都知道,在asp.net中修改了配置文件web.config后,会导致应用程序重启,所有会话(session)丢失.然而,应用程序的配置信息放在配置文件里是最佳选择,在后台修改了配置后导致所有会话 ...
- 在Web.Config文件中使用configSource,避免动态修改web.config导致asp.net重启(另添加一个Config文件用于管理用户数据)
原文:在Web.Config文件中使用configSource,避免动态修改web.config导致asp.net重启(另添加一个Config文件用于管理用户数据) 我们都知道,在asp.net中修改 ...
随机推荐
- case when遇到空串转成0
须要注意:假设字段为varchar类型,when后的条件要加上引號 SELECT (CASE marital_status WHEN 0 THEN '已婚' WHEN 1 THEN '未婚' ELSE ...
- linux tar.gz zip 解压缩 压缩命令
http://apps.hi.baidu.com/share/detail/37384818 download ADT link http://dl.google.com/android/ADT-0. ...
- xmf 翻译
避免在详细信息视图的确认对话框显示? https://documentation.devexpress.com/#Xaf/CustomDocument3160 我如何获得从登录窗口应用程序的数据库? ...
- [Angular2 Form] Use RxJS Streams with Angular 2 Forms
Angular 2 forms provide RxJS streams for you to work with the data and validity as it flows out of t ...
- 一款基于jQuery/CSS3实现拼图效果的相册
之前为大家介绍了 HTML5 3D立体图片相册, HTML5图片相册重力感应特效, 基于CSS3图片可倾斜摆放的动画相册 今天我们要来分享一款很酷的jQuery相册插件,首先相册中的图片会以一定的角度 ...
- 项目源码--Android类似酷狗音乐播放器
下载源码 知识技能概要: 1.音乐文件的扫描与管理 2.音频流的解码 3. UI控件的综合使用 4.播放列表方式管理 5.随机播放方式 6.源码带详细的中文注释 ...... 详细介绍 1. 音乐文件 ...
- Linux 的启动流程
转载:http://www.ruanyifeng.com/blog/2013/08/linux_boot_process.html 更多文档参见:http://pan.baidu.com/s/1hqo ...
- python 接口测试 、提交数据
在测试过程中经常会遇见需要向服务器提交数据.或者进行接口测试,这个有很多方法,但是我经常用的就是使用python 编写脚本提交,方便.说说方法: 思路: 1.首先有一个提交数据的url 2.按照字典的 ...
- 1.5.7 CharFilterFactories
CharFilterFactories 字符过滤器是一个预处理输入字符的组件,字符过滤器可以链接如token过滤器,并放置在Tokenizer(分词器)的前面,字符过滤器可以添加,更改或删除字符,同时 ...
- 使用异步httpclient框架做get,post提交数据
1.将异步httpclient框架导入 下载地址:http://download.csdn.net/detail/sinat_32804317/9555641 2.代码实现 public class ...