zoukankan      html  css  js  c++  java
  • Enterprise Library 4.1学习笔记 配置应用程序块(c/s和b/s均适用)

    This QuickStart does not use Enterprise Library. It is intended to provide guidance to users of previous versions of the Enterprise Library Configuration Application Block on how to migrate to the new features in System.Configuration in the .NET Framework 2.0.
    The Configuration functionality in the Enterprise Library Core provides services to the other blocks in the library and is not normally needed in user code.

    大意是:Configuration Application Block这个模块现在已经合并到.Net 2.0 System.Configuration中了,所以EL中不再单独保留这一模块,也就是说这部分功能完全用.net 2.0自带的功能就可实现

    应用场景:有时候,我们希望把某些类能序列化保存在app.config或web.config中,并能读写。

    使用步骤:

    1.先定义希望序列化保存的类,注意要继承自ConfigurationSection,示例代码如下:

    Code

    2.写入配置


     

    Code

    注意:这是winform(c/s)下的代码,如果是网站web应用,这样是会出错的!
    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    要改成下面这样
    string _ConfigPath = Server.MapPath("web");//如果这里web改为web.config,最终会生成一个新的web.config.config的文件,所以这里必须在根目录下新建一个名为"web"(注意不带扩展名)文本文件,然后系统才会正确写到web.config中,能想到这招骗过系统,我太有才啦^_^
    Configuration config = ConfigurationManager.OpenExeConfiguration(_ConfigPath);
    3.读取配置

    Code

    另外当配置更改(也就是配置值被修改)时,可以利用FileSystemWatcher监听实现触发某一事件,详情可见\EntLib41Src\Quick Starts\Configuration-Migration示例程序

  • 相关阅读:
    体温登记APP总结
    体温登记day4
    体温登记day3
    寒期周总结五
    体温登记day2
    体温登记day1
    家庭记账本day7
    家庭记账本day6
    家庭记账本day5
    家庭记账本day4
  • 原文地址:https://www.cnblogs.com/mikechang/p/1571558.html
Copyright © 2011-2022 走看看