web.config configSections自定义section
1、web.config 配置文件设置
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture= neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- type="类型,命名空间" -->
<section name="securevalid" type="JXAPI.JXSdk.Config.SecureConfigSection,JXAPI.JXSdk" />
</configSections>
<securevalid ipvalid="">
<secures>
<add source="other" pwd="" url="http://xxxx/" ip="192.168.0.1,127.0.0.1"></add>
<add source="employee" pwd="" url="http://xxxx.com/employee/get" ip=""></add>
</secures>
</securevalid>
2、SecureConfigSection 类
namespace JXAPI.JXSdk.Config
{
public class SecureConfigSection : ConfigurationSection
{
private static SecureConfigSection _Instance = null; public static SecureConfigSection Instance
{
get
{
if (_Instance == null)
{
_Instance = ConfigurationManager.GetSection("securevalid") as SecureConfigSection;
}
return _Instance;
}
} [ConfigurationProperty("ipvalid", IsRequired = true)]
public string IPValid
{
get
{
return this["ipvalid"].ToString();
}
} [ConfigurationProperty("secures", IsDefaultCollection = true)]
public SecureCollection Secures
{
get { return this["secures"] as SecureCollection; }
} } public class SecureCollection : ConfigurationElementCollection
{
protected override ConfigurationElement CreateNewElement()
{
return new SecureElement();
}
protected override object GetElementKey(ConfigurationElement element)
{
return ((SecureElement)element).Source;
} public SecureElement this[int index]
{
get
{
return this.BaseGet(index) as SecureElement;
}
}
new public SecureElement this[string Name]
{
get
{
return (SecureElement)BaseGet(Name);
}
}
new public int Count
{
get { return base.Count; }
}
} public class SecureElement : ConfigurationElement
{
[ConfigurationProperty("source", IsRequired = true)]
public string Source
{
get { return this["source"].ToString(); }
} [ConfigurationProperty("pwd", IsRequired = true)]
public string APPPWD
{
get { return this["pwd"].ToString(); }
} [ConfigurationProperty("url", IsRequired = true)]
public string URL
{
get { return this["url"].ToString(); }
} [ConfigurationProperty("ip", IsRequired = true)]
public string IP
{
get { return this["ip"].ToString(); }
}
}
}
3、应用
var url = JXAPI.JXSdk.Config.SecureConfigSection.Instance.Secures["employee"].URL;
var ip = JXAPI.JXSdk.Config.SecureConfigSection.Instance.Secures["other"].IP;
var ipValid = JXAPI.JXSdk.Config.SecureConfigSection.Instance.IPValid
web.config configSections自定义section的更多相关文章
- ASP.NET使用ConfigurationSection在Web.Config创建自定义配置节
主要代码,一定要继续System.Configuration.ConfigurationSection,具体的节点名称可以自行修改 using System; using System.Data; u ...
- ASP.NET使用ConfigurationSection在Web.Config创建自定义配置节集合
核心代码 using System; using System.Data; using System.Configuration; using System.Web; using System.Web ...
- Web.config配置configSections学习
文章:c# 配置文件之configSections配置 configSections节点需要位于configuration第一的位置,紧挨configuration. <configuratio ...
- ASP.NET Web.config
分析: .NET Web 应用程序的配置信息(如最常用的设置ASP.Net Web 应用程序的身份验证方式),它可以出现在应用程序的每一个目录中.当你通过VB.NET新 建 一个Web应用程序后,默认 ...
- C# 自定义Section
一.在App.config中自定义Section,这个使用了SectionGroup <?xml version="1.0" encoding="utf-8&quo ...
- ASP.NET Web.config文件的配置(Configuration API)
本次我们讨论主要聚焦在以下Web.config配置文件的设置值的读取. 1.<connectionString />连接字符串的读取. 2.<appSettings />应用程 ...
- 描述 Machine.Config 和 Web.Config(转载)
NET Framework 提供的配置管理包括范围广泛的设置,允许管理员管理 Web 应用程序及其环境.这些设置存储在 XML 配置文件中,其中一些控制计算机范围的设置,另一些控制应用程序特定的配置. ...
- 10 Things ASP.NET Developers Should Know About Web.config Inheritance and Overrides(转)
10 Things ASP.NET Developers Should Know About Web.config Inheritance and Overrides Wednesday, Janua ...
- Web.config自定义节点configSections
1.为什么需要自定义节点 为了增加应用程序的可移植性,通常网站需要配置一些自定义的节点,例如:文件上传的路径等,再深入的应用,可以定义工厂方法需要创建的类. 2.configSections使用方法 ...
随机推荐
- oracle常用查询三
查询跟索引有关的数据字典时,可以用下面这条SQL语句: SQL>select * from dictionary where instr(comments,'index')>0; 如果我们 ...
- 教训:TOJ[4081] God Le wants to know the directory
以前的字符串题本来就弱..2年不写就更弱了.嗯.留作教训 God Le is the most talented ACMer in the TJU-ACM team. When he wants to ...
- 【二分图最大匹配】【HDU2063】过山车
[科普]什么是BestCoder?如何参加? 过山车 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- nat网络穿透整理笔记(思维导图)
mindmanger整理的,关于Nat穿透,图片太小,可以点击放大,单独看图片.
- css权重计算
第一等:代表内联样式,如: style=””,权值为1000. 第二等:代表ID选择器,如:#content,权值为100. 第三等:代表类,伪类和属性选择器,如.content,权值为1 ...
- 使用一个HttpModule拦截Http请求,来检测页面刷新(F5或正常的请求)
在Web Application中,有个问题就是:“我怎么来判断一个http请求到底是通过按F5刷新的请求还是正常的提交请求?” 相信了解ASP.NET的人知道我在说什么,会有同感,而且这其实不是一个 ...
- 整理js继承
实现继承的方法: 一,原型链:利用原型让一个引用类型继承另一个引用类型的属性和方法 function SuperType(){ this.property=true; } SuperType.prot ...
- wamp出现问题#1045 - Access denied for user 'root'@'localhost' (using password: NO)的解决方法
打开wamp->apps->phpmyadmin目录下面的config.inc.php文件 cfg['Servers'][$i]['verbose'] = 'localhost';$cfg ...
- python核心编程-第五章-个人笔记
1.用del删除对对象的引用 >>> a = 123 >>> a 123 >>> del a >>> a Traceback ( ...
- How Many Tables--hdu1213(并查集)
How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...