1)web.config 文件内容如下:

<configuration>
<configSections>
<sectionGroup name="KaiXinSectionGroup">
<section name="KaiXinSection" type="WebApplication1.RewriterConfigSection"/> <!--type 为类RewriterConfigSection的路径-->
</sectionGroup>
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<KaiXinSectionGroup>
<KaiXinSection>
<add key="AppKey" value=""/>
<add key="AppSecret" value=""/>
<add key="SCOPE" value="basic"/>
</KaiXinSection>
</KaiXinSectionGroup>
</configuration>

2)添加一个类文件ConfigurationHelper.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration; namespace WebApplication1
{
public class ConfigurationHelper
{
} public class RewriterConfigSection : ConfigurationSection
{
[ConfigurationProperty("", IsDefaultCollection = true)]
public RewriterRuleElementCollection MySection
{
get { return (RewriterRuleElementCollection)base[""]; }
}
} public class RewriterRuleElement : ConfigurationElement
{
[ConfigurationProperty("key", IsRequired = true)]
public string Key
{
get { return (string)base["key"]; }
set { base["key"] = value; }
}
[ConfigurationProperty("value", IsRequired = true)]
public string Value
{
get { return (string)base["value"]; }
} }
public class RewriterRuleElementCollection : ConfigurationElementCollection
{
public RewriterRuleElementCollection()
{
RewriterRuleElement rrElement = CreateNewElement() as RewriterRuleElement;
BaseAdd(rrElement);
}
protected override ConfigurationElement CreateNewElement()
{
return new RewriterRuleElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((RewriterRuleElement)element).Key;
} protected override string ElementName
{
get
{
return "add";
}
}
public override ConfigurationElementCollectionType CollectionType
{
get
{
return ConfigurationElementCollectionType.BasicMap;
}
}
public RewriterRuleElement this[int index]
{
get { return (RewriterRuleElement)BaseGet(index); }
}
public new RewriterRuleElement this[string name]
{
get { return (RewriterRuleElement)BaseGet(name); }
} }
}

3)获取SessionGroup里的值

   public RewriterConfigSection Section { get; set; }
protected void Button1_Click(object sender, EventArgs e)
{ Section = (RewriterConfigSection)ConfigurationManager.GetSection("KaiXinSectionGroup/KaiXinSection");
string a = Section.MySection["AppKey"].Value;
string b = Section.MySection["AppSecret"].Value;
string c = Section.MySection["SCOPE"].Value;
}

获取web.config配置文件的sectionGroup的更多相关文章

  1. C# 获取web.config配置文件内容

    1.web.config提供对客户端应用程序配置文件的访问. 其有两个属性1.ConnectionStrings 获取当前应用程序默认配置的 ConnectionStringsSection 数据. ...

  2. C# 获取web.config配置文件

    .ConfigurationManager提供对客户端应用程序配置文件的访问. 其有两个属性1.ConnectionStrings 获取当前应用程序默认配置的 ConnectionStringsSec ...

  3. c#代码获取web.config配置文件里面设置的 <compilation debug="true"节点

    == 在我们的web.config文件中,有像下面的这样的一个配置, <system.web> <identity impersonate="true" user ...

  4. Web.config配置文件详解

    整理了一下ASP.NET Web.config配置文件的基本使用方法.很适合新手参看,由于Web.config在使用很灵活,可以自定义一些节点.所以这里只介绍一些比较常用的节点. <?xml v ...

  5. [转]Web.config配置文件详解(新手必看)

    本文转自:http://www.cnblogs.com/gaoweipeng/archive/2009/05/17/1458762.html 花了点时间整理了一下ASP.NET Web.config配 ...

  6. 转:Web.config配置文件详解(新手必看)

    转:http://www.cnblogs.com/gaoweipeng/archive/2009/05/17/1458762.html 花了点时间整理了一下ASP.NET Web.config配置文件 ...

  7. Web.config配置文件详解(新手必看)

    花了点时间整理了一下ASP.NET Web.config配置文件的基本使用方法.很适合新手参看,由于Web.config在使用很灵活,可以自定义一些节点.所以这里只介绍一些比较常用的节点. <? ...

  8. (转)Web.config配置文件详解(新手必看)

    花了点时间整理了一下ASP.NET Web.config配置文件的基本使用方法.很适合新手参看,由于Web.config在使用很灵活,可以自定义一些节点.所以这里只介绍一些比较常用的节点. <? ...

  9. Asp.net中web.config配置文件详解(一)

    本文摘自Asp.net中web.config配置文件详解 web.config是一个XML文件,用来储存Asp.NET Web应用程序的配置信息,包括数据库连接字符.身份安全验证等,可以出现在Asp. ...

随机推荐

  1. Loadrunner--web_find和web_reg_find的用法和区别

    一.web_find()函数 该函数的作用是“在页面中查找相应的内容”,常用参数及含义如下: web_find("web_find", //定义该查找函数的名称 "Rig ...

  2. mongodb查询部分满足条件的列

    db.tblorders.createIndex( { orderid : -1 },{background:true, name:"index_orderid"} ); db.o ...

  3. js读取json,纠结。。。

    什么是json.先小抄一段:  JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.採用全然独立于语言的文本格式, 是理想的数据交换格式,同一时候,JSO ...

  4. spark原理介绍 分类: B8_SPARK 2015-04-28 12:33 1039人阅读 评论(0) 收藏

    1.spark是一个基于内存计算的开源的集群计算系统,目的是让数据分析更加快速.因此运行spark的机器应该尽量的大内存,如96G以上. 2.spark所有操作均基于RDD,操作主要分成2大类:tra ...

  5. 22、DMA驱动程序框架

    一.使用DMA的优点及DMA支持的请求源(请求源是启动DMA传输的事件,可以认为是触发.它可以是软件,也可以是中断,或者外部事件) 1.DMA优点是其进行数据传输时不需要CPU的干涉,可以大大提高CP ...

  6. css 单行图片文字水平垂直居中汇总

    (1) 水平居中 a. 行内元素水平居中 因为img是行内元素(行内块级元素也一样)父级元素设置text-align:center即可,例如: <div style="width: 6 ...

  7. Envelope

    IEnvelope Interface Provides access to methods and properties of envelopes. Note: the IEnvelope inte ...

  8. python类继承时构造函数的运行问题

    假设子类定义了自己的__init__构造方法函数.当子类的实例对象被创建时,子类仅仅会运行自己的__init__方法函数.假设子类没有定义自己的构造方法函数.会沿着搜索树找到父类的构造方法函数去运行父 ...

  9. vuejs及相关工具介绍

    轻量级前端mvm的框架 图片.png 对es6语法的简单描述 图片.png 融合了react和angular的优点,组件化和灵活应用和指令,在国际上是一款极有潜力的前端框架. 1.双向绑定 两段相加得 ...

  10. Java NIO的基本概念与使用

    public class TestBuffer { /** * 一. 缓冲区 (Buffer):Java Nio中负责数据的 存取+缓冲就是数组.用于存储不同类型的数据 * * 根据类型不同(bool ...