这篇文章主要介绍在web.config或者app.config中如何增加自定义配置节,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

简单键值对
web.config
users.config
c#
NameValueCollection users = System.Configuration.ConfigurationManager.GetSection("users") as NameValueCollection;
Response.Write(users.Keys[0]+""+users.Keys[1]);复杂类型
web.config
roles.config
RolesCofig.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EBuy.Chapter3.NTier.WebUI
{
public class RolesConfig : System.Configuration.IConfigurationSectionHandler
{
public object Create(object parent, object configContext, System.Xml.XmlNode section)
{
return section;
}
}
}c#
XmlNode roles= System.Configuration.ConfigurationManager.GetSection("roles") as XmlNode;
Response.Write(roles.ChildNodes [0].Attributes["username"].InnerText);还可以将配置节定义为一个实体
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EBuy.Chapter3.NTier.WebUI
{
public class RolesConfig : System.Configuration.IConfigurationSectionHandler
{
public object Create(object parent, object configContext, System.Xml.XmlNode section)
{
var list=new List();
for(int i=0;ivar roles = System.Configuration.ConfigurationManager.GetSection("roles") as List;
Response.Write(roles.First ().Username); 以上是“在web.config或者app.config中如何增加自定义配置节”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联网站制作公司行业资讯频道!
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。
新闻名称:在web.config或者app.config中如何增加自定义配置节-创新互联
网站链接:http://cdysf.com/article/dceihe.html