代码之家  ›  专栏  ›  技术社区  ›  dexter

asp.net应用程序-配置实现

  •  0
  • dexter  · 技术社区  · 15 年前

    需要能够序列化集合,选择文件写入事件以将配置的新实例重新加载到内存中。

    1 回复  |  直到 15 年前
        1
  •  0
  •   Matthew Abbott    15 年前

    您查看过System.Configuration命名空间吗?创建ConfigurationSection、ConfigurationElement和ConfigurationElementCollection实例相对来说比较轻松。罗拉的那4个人 blogged

    这种方法需要注意的一点是,当您更改web.config时,应用程序会自动为您回收#

    更新 实际上,您可以将配置分离为单独的.config文件。你还需要申报 <section> <sectionGroup> 主web.config文件中的元素,但继承自 ConfigurationSection 支持 configSource 财产。例如。:

    <?xml version="1.0" encoding="UTF-8" ?>
    <configuration>
      <configSections>
        <section name="myConfigSection" type="..." />
      </configSections>
    
      <myConfigSection configSource="myConfigSection.config" />
    </configuration>
    

    然后你可以添加一个单独的 myConfigSection.config

    <?xml version="1.0" encoding="UTF-8" ?>
    <myConfigSection>
      <someElement />
    </myConfigSection>
    
    推荐文章