获取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. ...
随机推荐
- 【AtCoder Beginner Contest 074 D】Restoring Road Network
[链接]h在这里写链接 [题意] 给你任意两点之间的最短路. 让你求出原图. 或者输出原图不存在. 输出原图的边长总和的最小值. [题解] floyd算法. 先在原有的矩阵上. 做一遍floyd. 如 ...
- UVA10006 - Carmichael Numbers(筛选构造素数表+高速幂)
UVA10006 - Carmichael Numbers(筛选构造素数表+高速幂) 题目链接 题目大意:假设有一个合数.然后它满足随意大于1小于n的整数a, 满足a^n%n = a;这种合数叫做Ca ...
- 异步载入JS
平时最常使用的就是这样的同步载入形式: <script src="http://yourdomain.com/script.js"></script&g ...
- iOS图片加载-SDWebImage
一.SDWebImage内部实现过程 1, 入口 setImageWithURL:placeholderImage:options: 会先把 placeholderImage 显示,然后 SDWeb ...
- vc弹出USB的方法. 附试验通过的代码!
vc弹出USB的方法. 附试验通过的代码! http://blog.sina.com.cn/s/blog_4fcd1ea30100qrzn.html (2011-04-15 10:09:48) boo ...
- 无法顺利删除问题处理一则-ORA-00604和ORA-00942错误
1.以sys/oracle登录 2. -- Create tablecreate table ARGUMENT$( OBJ# NUMBER not null, PROCEDURE ...
- jquery常用方法总结(转)
取值与赋值操作 $("#ID").val(); //取value值 $("#ID").val("xxx"); //赋值 $("#I ...
- 【69.77%】【codeforces 723A】The New Year: Meeting Friends
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 阿里云服务器安全设置 分类: B3_LINUX 2014-07-24 11:10 5197人阅读 评论(1) 收藏
1.开启云盾所有服务 2.通过防火墙策略限制对外扫描行为 请您根据您的服务器操作系统,下载对应的脚本运行,运行后您的防火墙策略会封禁对外发包的行为,确保您的主机不会再出现恶意发包的情况,为您进行后续数 ...
- ios开发事件处理之 四:hittest方法的底层实现与应用
#import "XMGWindow.h" /** 1:注意点:hitTest方法内部会调用pointInside方法,询问触摸点是否在自己身上,当遍历子控件时,传入的坐标点要进行 ...