获取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. ...
随机推荐
- SQL判断空值、nvl处理与JOIN的使用
LIKE子句会影响查询性能,所以在明确知道字符个数时,应该使用'_',而不使用'%'. 判断空值/非空值 SELECT select_list FROM table_list/view_list WH ...
- 装饰模式和python装饰器
装饰器和装饰模式 先给出两者的定义: - 装饰器:装饰器是一个非常著名的设计模式,常常被用于有切面需求的场景.较为经典的有插入日志.性能測试.事务处理等. 装饰器是解决这类问题的绝佳设计.有了装饰器, ...
- 对inetd、xinetd与TCP_Wrapper的基本了解
在Linux系统中有一个特殊的守护进程inetd(InterNET services Daemon),它用于Internet标准服务,通常在系统启动时启动.通过命令行可以给出inetd的配置文件,该配 ...
- ITFriend月刊-第1期-2014年6月.pdf
ITFriend上线一个月了,积累了不少优质内容,本周进行了整理,制作了PDF格式的电子书. 欢迎大家下载阅读. 下载地址: CSDN下载:http://download.csdn.net/detai ...
- Docker搭建ES
Centos7安装ES 和 Docker搭建ES 文版权归博客园和作者吴双本人共同所有 转载和爬虫请注明原文地址 www.cnblogs.com/tdws 一.linux centos7.x安装ES ...
- stm32的复用与映射
摘自:https://blog.csdn.net/lincheng15/article/details/51789093 摘自:http://www.51hei.com/bbs/dpj-36242-1 ...
- 18、IIC总线驱动程序
i2c_s3c2410.c是内核自带dev层(adapt)驱动程序,知道怎么发收数据,不知道含义 在与i2c_s3c2410.c(在其probe函数中的s3c24xx_i2c_init函数会初始化ii ...
- Jupyter Notebook 常用快捷键
Jupyter Notebook 提供了比 IPython 美观的多得多的可视化形式.(比如对于 pandas 下的 DataFrame 的展示,df.head(5)) Jupyter Noteboo ...
- php thinkphp uploadify
模板文件: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w ...
- php解析xml字符串
<?php $content = <<<XML <?xml version="1.0" encoding="UTF-8"?> ...