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的更多相关文章

  1. ASP.NET使用ConfigurationSection在Web.Config创建自定义配置节

    主要代码,一定要继续System.Configuration.ConfigurationSection,具体的节点名称可以自行修改 using System; using System.Data; u ...

  2. ASP.NET使用ConfigurationSection在Web.Config创建自定义配置节集合

    核心代码 using System; using System.Data; using System.Configuration; using System.Web; using System.Web ...

  3. Web.config配置configSections学习

    文章:c# 配置文件之configSections配置 configSections节点需要位于configuration第一的位置,紧挨configuration. <configuratio ...

  4. ASP.NET Web.config

    分析: .NET Web 应用程序的配置信息(如最常用的设置ASP.Net Web 应用程序的身份验证方式),它可以出现在应用程序的每一个目录中.当你通过VB.NET新 建 一个Web应用程序后,默认 ...

  5. C# 自定义Section

    一.在App.config中自定义Section,这个使用了SectionGroup <?xml version="1.0" encoding="utf-8&quo ...

  6. ASP.NET Web.config文件的配置(Configuration API)

    本次我们讨论主要聚焦在以下Web.config配置文件的设置值的读取. 1.<connectionString />连接字符串的读取. 2.<appSettings />应用程 ...

  7. 描述 Machine.Config 和 Web.Config(转载)

    NET Framework 提供的配置管理包括范围广泛的设置,允许管理员管理 Web 应用程序及其环境.这些设置存储在 XML 配置文件中,其中一些控制计算机范围的设置,另一些控制应用程序特定的配置. ...

  8. 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 ...

  9. Web.config自定义节点configSections

    1.为什么需要自定义节点 为了增加应用程序的可移植性,通常网站需要配置一些自定义的节点,例如:文件上传的路径等,再深入的应用,可以定义工厂方法需要创建的类. 2.configSections使用方法 ...

随机推荐

  1. MySQL中explain的type类型

    |  ALL              |  全表扫描 |  index            |  索引全扫描 |  range            |  索引范围扫描,常用语<,<= ...

  2. AliCTF 2016

    上上周参加了阿里的CTF,靠着最后绝杀队伍有幸拿到了国内第一名,也顺利进入了XCTF Final.把自己做的几个题简单写了下,发出来也算个总结吧. PWN-FB 经典的null byte overfl ...

  3. 克隆虚拟机,如何将克隆虚拟的网卡设置为eth0

    1.先删掉/etc/udev/rules.d/70-persistent-net.rules文件里的eth0,并要记住eth1的那个网卡的mac地址等下要用.2.把那个eth1修改为eth03.编辑网 ...

  4. 在IIS上Office Word下载失败,检索 COM 类工厂中 CLSID 为000209FF的组件失败,80070005 拒绝访问。

    最近在做一个网站时,有一个下载word文档功能,在本地直接调试是可以下载的,但部署到IIS上就出现问题了. 出现问题如下:Error:下载简历方法出错:检索 COM 类工厂中 CLSID 为 {000 ...

  5. UILabel + 导入字体

    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 100)]; 1.设置文字颜色 label.textC ...

  6. 在Javascript中使用String.startsWith和endsWith

    在Javascript中使用String.startsWith和endsWith 在操作字符串(String)类型的时候,startsWith(anotherString)和endsWith(anot ...

  7. Visual Studio 2008快捷键

    命令行:Devenv 启动VS StudionIsqlw 启动SQL2000查询分析器Sqlwb 启动SQL2005企业管理器Inetmgr 启动IIS管理器大纲Ctrl+M,O折叠所有大纲Ctrl+ ...

  8. MySQL高效获取记录总数

    通常mysql获取查询记录总数我们使用如下语句: SELECT COUNT(*) FROM users WHERE k='avs';  或:SELECT id FROM goods WHERE k=' ...

  9. 1021 Fibonacci Again (hdoj)

    Problem Description There are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) ...

  10. UVA 12563 Jin Ge Jin Qu hao

    dp-背包 开始用普通dp写了一发发现没法确定最大时间... 后来看到大牛机智的写法,嗯...dp表示当前状态能否成立:然后从条件最好的状态开始遍历,直到这个状态成立然后退出遍历. 具体的看代码吧.. ...