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. Day2:字符串常用方法

    字符串常用方法 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan name = "my \tname is ...

  2. Node.js自学笔记之回调函数

    写在前面:如果你是一个前端程序员,你不懂得像PHP.Python或Ruby等动态编程语言,然后你想创建自己的服务,那么Node.js是一个非常好的选择.这段时间对node.js进行了简单的学习,在这里 ...

  3. 【AtCoder Beginner Contest 074 A】Bichrome Cells

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] 在这里写题解 [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/stdc++.h> using n ...

  4. [D3] Create Chart Axes with D3 v4

    Most charts aren’t complete without axes to provide context and labeling for the graphical elements ...

  5. 7 Java Performance Metrics to Watch After a Major Release--转

    原文地址:https://dzone.com/articles/7-java-performance-metrics-to-watch-after-a-major-1 The Java perform ...

  6. Oracle Web链接客户端

    TreeSoft数据库管理系统 http://www.treesoft.cn        

  7. Linux中U盘和SD卡加载卸载命令

    U盘挂载命令U盘插入的时候会显示启动信息,启动信息中sda: sda1指U盘的设备名为sda1dev设备目录下有一个sda1设备文件,此设备文件就是我们插入的U盘,我们将这个设备文件挂载到Linux系 ...

  8. like小计

    1.有索引的列最好进行 ‘aa%’形式可以使用一些索引. 2.如果非得进行 ‘%aa%’这种类型查询,那这个条件不要进行主要过滤条件. 意思是这个列如果有索引就不能用索引,即使用了,索引页是进行对整个 ...

  9. 7、linux系统2440开发板域名解析问题

    如果在linux系统中ping某一台电脑的ip地址可以ping 通: ~ >: ping 192.168.1.3PING 192.168.1.3 (192.168.1.3): 56 data b ...

  10. Tomcat请求处理过程(Tomcat源代码解析五)

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/ ...