获取web.config配置文件的sectionGroup
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的更多相关文章
- C# 获取web.config配置文件内容
1.web.config提供对客户端应用程序配置文件的访问. 其有两个属性1.ConnectionStrings 获取当前应用程序默认配置的 ConnectionStringsSection 数据. ...
- C# 获取web.config配置文件
.ConfigurationManager提供对客户端应用程序配置文件的访问. 其有两个属性1.ConnectionStrings 获取当前应用程序默认配置的 ConnectionStringsSec ...
- c#代码获取web.config配置文件里面设置的 <compilation debug="true"节点
== 在我们的web.config文件中,有像下面的这样的一个配置, <system.web> <identity impersonate="true" user ...
- Web.config配置文件详解
整理了一下ASP.NET Web.config配置文件的基本使用方法.很适合新手参看,由于Web.config在使用很灵活,可以自定义一些节点.所以这里只介绍一些比较常用的节点. <?xml v ...
- [转]Web.config配置文件详解(新手必看)
本文转自:http://www.cnblogs.com/gaoweipeng/archive/2009/05/17/1458762.html 花了点时间整理了一下ASP.NET Web.config配 ...
- 转:Web.config配置文件详解(新手必看)
转:http://www.cnblogs.com/gaoweipeng/archive/2009/05/17/1458762.html 花了点时间整理了一下ASP.NET Web.config配置文件 ...
- Web.config配置文件详解(新手必看)
花了点时间整理了一下ASP.NET Web.config配置文件的基本使用方法.很适合新手参看,由于Web.config在使用很灵活,可以自定义一些节点.所以这里只介绍一些比较常用的节点. <? ...
- (转)Web.config配置文件详解(新手必看)
花了点时间整理了一下ASP.NET Web.config配置文件的基本使用方法.很适合新手参看,由于Web.config在使用很灵活,可以自定义一些节点.所以这里只介绍一些比较常用的节点. <? ...
- Asp.net中web.config配置文件详解(一)
本文摘自Asp.net中web.config配置文件详解 web.config是一个XML文件,用来储存Asp.NET Web应用程序的配置信息,包括数据库连接字符.身份安全验证等,可以出现在Asp. ...
随机推荐
- WPF学习笔记——概述
如果你选择WPF,多半原因是因为折服于它那震撼性的用户体验.纵观WPF整个知识体系,其内容并不复杂,但却比较细碎,不易理清.以下内容是对WPF部分内容的简单概括,希望读者能够对WPF框架有个大体认识. ...
- Makefile中支持的函数大全
一.描述 Makefile的函数调用,很像变量的使用,也是以"$"来标识的,其语法如下: $(<function> <arguments> ) 或是 ${& ...
- POJ 2402 Palindrome Numbers(LA 2889) 回文数
POJ:http://poj.org/problem?id=2402 LA:https://icpcarchive.ecs.baylor.edu/index.php?option=com_online ...
- ARM+linux学习过程(1)虚拟机下ubuntu上网
总结:(1)通过bridge方式也可以实现ubuntu上网(只要PC物理网卡能上网),可以实现ping通主机和开发板 (2)要想上网简单上网,可以通过nat方式,在vmware中设置为nat方式,选择 ...
- 【奇葩笔试】—— printf() 作为函数的参数及其返回值
int f(int a, int b, int c){ return 0; } int main(int, char**){ f(printf("a"), printf(" ...
- PHP中出现BOM字符\ufeff,PHP去掉诡异的BOM \ufeff
研究一个PHP项目的时候,今天项目突然打不开了. 前几天还好好的,用Chrome看了下Response的内容,AJAX页面和普通HTML页面内容前面有一个红色的点. 鼠标移上去,提示"\uf ...
- C++中string类的操作函数。
相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有没有这样使用起来非常方便的类呢?答案是肯 ...
- Android多线程研究(8)——Java5中Futrue获取线程返回结果
我们先来看一下ExecutorService中的执行方法: 在上一篇中我们使用了execute方法启动线程池中的线程执行,这一篇我们来看看submit方法的使用:submit提交一个返回值的任务用于执 ...
- 摘录-Mybatis - Integer值为0的数据 return false
Mybatis在进行<if test="status != null and status != ''">判空操作时,如果status为0的时候,该判断条件的值为fal ...
- Freemarker中的null判断,小坑一枚
上次写到,在Freemarker中日期转换,可以提取成工具方法.主要是Freemarker对null的处理方式,非常坑爹.只要一个对象或对象的属性为null,就报错,虽然不影响界面显示,但控制台和日志 ...