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 5.7忘记密码处理

    vi /etc/my.cnf在[mysqld]下面增加一行skip-grant-tables 重启  /etc/init.d/mysqld restart /usr/local/mysql/bin/m ...

  2. AlertDialog详解

    参考地址:http://blog.csdn.net/woaieillen/article/details/7378324 1.弹出提示框 new AlertDialog.Builder(LoginAc ...

  3. NET基础课--JIT编译器如何工作1

    1..Net运行时调用JIT编译器,用来把由C#编译器生成的IL指令编译成机器代码.这一任务在应用程序的运行期间是分步进行的.JIT并不是在程序一开始就编译整个应用程序,取而代之的是,CLR是一个函数 ...

  4. escape和unescape给字符串编码

    var before = "\xxx\xxx" var after = escape(before); var after2 = unescape(after );

  5. JSP基础之 C标签中的 varStatues属性

    变量状态参数,该属性有5个常用值count 表示当前遍历集合的元素个数index 表示当前遍历到集合的第几个元素current 表示当前的集合元素first 表示集合的第一个元素last 表示集合的最 ...

  6. HDU 5145 - NPY and girls

    题意: cases T(1≤T≤10) (0<n,m≤30000) (0<ai≤30000)    n个数ai 表示n个女孩所在教室 m次询问 [L,R](1 <= L <= ...

  7. setlocal enabledelayedexpansion

    http://www.jb51.net/article/29323.htm 例1: 代码如下: @echo off set a=4 set a=5&echo %a% pause  结果:4 解 ...

  8. celery 使用multiprocessing 问题记录

    报错: [2013-11-29 14:27:48,297: ERROR/MainProcess] Task app.add[e5d184c0-471f-4fc4-804c-f760178d4847] ...

  9. Jumpserver

    Jumpserver 是一款由python编写开源的跳板机(堡垒机)系统,实现了跳板机应有的功能.基于ssh协议来管理,客户端无需安装agent. 支持常见系统: redhat centos debi ...

  10. pycares cffi

    pypy 5.0.1 由于 cpyext 有 bug,用不了异步 DNS 解析库 pycares .花了一周时间,对照着 pycares 的 C 代码自己重写了个 cffi 的实现.在 windows ...