读取webconfig中自定义的xml  处理对特定的配置节的访问。

webconfig

   <configSections>
<section name="NopConfig" type="BotanicSystem.Core.Configuration.NopConfig, BotanicSystem.Core" requirePermission="false" />
</configSections>
   <NopConfig>
<!-- Web farm support
Enable "MultipleInstancesEnabled" if you run multiple instances.
Enable "RunOnAzureWebsites" if you run on Windows Azure Web sites (not cloud services). -->
<WebFarms MultipleInstancesEnabled="False" RunOnAzureWebsites="False" />
<!-- Windows Azure BLOB storage. Specify your connection string, container name, end point for BLOB storage here -->
<AzureBlobStorage ConnectionString="" ContainerName="" EndPoint="" />
<!-- Redis support (used by web farms, Azure, etc). Find more about it at https://azure.microsoft.com/en-us/documentation/articles/cache-dotnet-how-to-use-azure-redis-cache/ -->
<RedisCaching Enabled="false" ConnectionString="localhost" />
<!-- You can get the latest version of user agent strings at http://browscap.org/ -->
<UserAgentStrings databasePath="~/App_Data/browscap.xml" />
<!-- Set the setting below to "False" if you did not upgrade from one of the previous versions. It can slightly improve performance -->
<SupportPreviousNopcommerceVersions Enabled="True" />
<!-- Do not edit this element. For advanced users only -->
<Installation DisableSampleDataDuringInstallation="False" UseFastInstallationService="False" PluginsIgnoredDuringInstallation="" />
</NopConfig>

解析读取

     /// <summary>
/// Represents a NopConfig
/// </summary>
public partial class NopConfig : IConfigurationSectionHandler
{
/// <summary>
/// Creates a configuration section handler.
/// </summary>
/// <param name="parent">Parent object.</param>
/// <param name="configContext">Configuration context object.</param>
/// <param name="section">Section XML node.</param>
/// <returns>The created section handler object.</returns>
public object Create(object parent, object configContext, XmlNode section)
{
var config = new NopConfig(); var startupNode = section.SelectSingleNode("Startup");
config.IgnoreStartupTasks = GetBool(startupNode, "IgnoreStartupTasks"); var redisCachingNode = section.SelectSingleNode("RedisCaching");
config.RedisCachingEnabled = GetBool(redisCachingNode, "Enabled");
config.RedisCachingConnectionString = GetString(redisCachingNode, "ConnectionString"); var userAgentStringsNode = section.SelectSingleNode("UserAgentStrings");
config.UserAgentStringsPath = GetString(userAgentStringsNode, "databasePath"); var supportPreviousNopcommerceVersionsNode = section.SelectSingleNode("SupportPreviousNopcommerceVersions");
config.SupportPreviousNopcommerceVersions = GetBool(supportPreviousNopcommerceVersionsNode, "Enabled"); var webFarmsNode = section.SelectSingleNode("WebFarms");
config.MultipleInstancesEnabled = GetBool(webFarmsNode, "MultipleInstancesEnabled");
config.RunOnAzureWebsites = GetBool(webFarmsNode, "RunOnAzureWebsites"); var azureBlobStorageNode = section.SelectSingleNode("AzureBlobStorage");
config.AzureBlobStorageConnectionString = GetString(azureBlobStorageNode, "ConnectionString");
config.AzureBlobStorageContainerName = GetString(azureBlobStorageNode, "ContainerName");
config.AzureBlobStorageEndPoint = GetString(azureBlobStorageNode, "EndPoint"); var installationNode = section.SelectSingleNode("Installation");
config.DisableSampleDataDuringInstallation = GetBool(installationNode, "DisableSampleDataDuringInstallation");
config.UseFastInstallationService = GetBool(installationNode, "UseFastInstallationService");
config.PluginsIgnoredDuringInstallation = GetString(installationNode, "PluginsIgnoredDuringInstallation"); return config;
} private string GetString(XmlNode node, string attrName)
{
return SetByXElement<string>(node, attrName, Convert.ToString);
} private bool GetBool(XmlNode node, string attrName)
{
return SetByXElement<bool>(node, attrName, Convert.ToBoolean);
} private T SetByXElement<T>(XmlNode node, string attrName, Func<string, T> converter)
{
if (node == null || node.Attributes == null) return default(T);
var attr = node.Attributes[attrName];
if (attr == null) return default(T);
var attrVal = attr.Value;
return converter(attrVal);
} /// <summary>
/// Indicates whether we should ignore startup tasks
/// </summary>
public bool IgnoreStartupTasks { get; private set; } /// <summary>
/// Path to database with user agent strings
/// </summary>
public string UserAgentStringsPath { get; private set; } /// <summary>
/// Indicates whether we should use Redis server for caching (instead of default in-memory caching)
/// </summary>
public bool RedisCachingEnabled { get; private set; }
/// <summary>
/// Redis connection string. Used when Redis caching is enabled
/// </summary>
public string RedisCachingConnectionString { get; private set; } /// <summary>
/// Indicates whether we should support previous nopCommerce versions (it can slightly improve performance)
/// </summary>
public bool SupportPreviousNopcommerceVersions { get; private set; } /// <summary>
/// A value indicating whether the site is run on multiple instances (e.g. web farm, Windows Azure with multiple instances, etc).
/// Do not enable it if you run on Azure but use one instance only
/// </summary>
public bool MultipleInstancesEnabled { get; private set; } /// <summary>
/// A value indicating whether the site is run on Windows Azure Websites
/// </summary>
public bool RunOnAzureWebsites { get; private set; } /// <summary>
/// Connection string for Azure BLOB storage
/// </summary>
public string AzureBlobStorageConnectionString { get; private set; }
/// <summary>
/// Container name for Azure BLOB storage
/// </summary>
public string AzureBlobStorageContainerName { get; private set; }
/// <summary>
/// End point for Azure BLOB storage
/// </summary>
public string AzureBlobStorageEndPoint { get; private set; } /// <summary>
/// A value indicating whether a store owner can install sample data during installation
/// </summary>
public bool DisableSampleDataDuringInstallation { get; private set; }
/// <summary>
/// By default this setting should always be set to "False" (only for advanced users)
/// </summary>
public bool UseFastInstallationService { get; private set; }
/// <summary>
/// A list of plugins ignored during nopCommerce installation
/// </summary>
public string PluginsIgnoredDuringInstallation { get; private set; }
}

使用

 var config = ConfigurationManager.GetSection("NopConfig") as NopConfig;

IConfigurationSectionHandler  是 在System.Configuration 下

IConfigurationSectionHandler 使用~的更多相关文章

  1. 使用IConfigurationSectionHandler在web.config中增加自定义配置

    一. 场景    这里仅举一个简单应用的例子,我希望在web.config里面增加网站的基本信息,如:网站名称,网站版本号,是否将网站暂时关闭等.二. 基本实现方法1. 定义配置节点对应的类:Site ...

  2. (转).net webconfig使用IConfigurationSectionHandler自定section

    自定义配置结构 (使用IConfigurationSectionHandler) 假设有以下的配置信息,其在MyInfo可以重复许多次,那么应如何读取配置呢?这时就要使用自定义的配置程序了.<m ...

  3. IConfigurationSectionHandler 接口

    IConfigurationSectionHandler 处理对特定的配置节的访问. 示例代码: public class MyConfig : IConfigurationSectionHandle ...

  4. .Net——实现IConfigurationSectionHandler接口定义处理程序处理自己定义节点

    除了使用.net里面提供的内置处理程序来处理我们的自己定义节点外,我们还能够通过多种方法,来自己定义处理类处理我们的自己定义节点,本文主要介绍通过实现IConfigurationSectionHand ...

  5. .Net——实现IConfigurationSectionHandler接口定义处理程序处理自定义节点

    除了使用.net里面提供的内置处理程序来处理我们的自定义节点外,我们还可以通过多种方法,来自己定义处理类处理我们的自定义节点,本文主要介绍通过实现IConfigurationSectionHandle ...

  6. spring.net 框架分析(三)ContextRegistry.GetContext()

    我们通过ContextRegistry.GetContext()建立了一个IApplicationContext得实例,那么这个实例具体是怎么建立的了. 我们来分析一下容器实例建立的过程: 我们在配置 ...

  7. C# 自定义Section

    一.在App.config中自定义Section,这个使用了SectionGroup <?xml version="1.0" encoding="utf-8&quo ...

  8. Url路径重写的原理

    ASP.net的地址重写(URLRewriter)实现原理及代码示例 吴剑 2007-01-01 原创文章,转载必需注明出处:http://www.cnblogs.com/wu-jian/ 概述 访问 ...

  9. 第13章 .NET应用程序配置

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...

随机推荐

  1. iOS开发——高级篇——远程音频、视频播放

    一.远程音频播放(<AVFoundation/AVFoundation.h>) #import <AVFoundation/AVFoundation.h> /** 播放器 */ ...

  2. App提交Appstore审核流程

    原文: https://www.douban.com/note/461351420/ 这是一个app提交到iTunces Connect被拒了4次摸索出来的经验,说多了都是泪,先让我擦擦...好了,话 ...

  3. Windows请求连接 Vmware+Ubuntu14被拒绝 的幽怨诉说

    最近为了学习Linux,在电脑上装了Vmware然后搭建了Ubuntu14的Linux操作系统 搭建完成以后,我兴冲冲的使用TeraTerm进行友情访问发现被拒绝,我很郁闷. 怎么可以这样呢. 然后调 ...

  4. orm 语法 数据库连接、建表、增删改查、回滚、单键关联 、多键关联、三表关联

    1.数据库连接, #!usr/bin/env/python # -*- coding:utf-8 -*- # from wangteng import sqlalchemy from sqlalche ...

  5. Magento 创建新的数据实体 model 、 resource 和 collection 文件

    一.创建model文件 class Bestbuy_PrepaidCard_Model_Used extends Mage_Core_Model_Abstract {       protected ...

  6. Outlook~设置

    outlook2013 中帐户设置无法直接更改邮件投递位置到本地的.pst文件,“更改文件夹”选项已经删除. Exchange 传递到 Outlook 数据文件 (.pst) 升级到 Outlook ...

  7. 0ctf – mobile – boomshakalaka writeup

    作为一个web狗,一道web都没做出来Orz...做出来一道apk,纪念一下在ctf中做出的第一道apk... 首先在模拟器或者真机中安装一下apk看到是一个cocos2dx的打飞机游戏 根据题目提示 ...

  8. assign more memory to Gradle

    Please assign more memory to Gradle in the project's gradle.properties file.For example, the followi ...

  9. 统一配置管理-百度disconf

    之前一直采用properties文件管理配置信息,若是集群则每个机器上都要拷贝一份,每次修改也需要依次修改.一直在寻找统一修改,实时生效,方便修改,分环境分系统的配置管理,自己也在整理设计,若找不到合 ...

  10. C语言中的强符号与弱符号

    转自:http://blog.csdn.net/astrotycoon/article/details/8008629 一.概述 在C语言中,函数和初始化的全局变量(包括显示初始化为0)是强符号,未初 ...