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

10年的施秉网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。成都营销网站建设的优势是能够根据用户设备显示端的尺寸不同,自动调整施秉建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联建站从事“施秉网站设计”,“施秉网站推广”以来,每个客户项目都认真落实执行。
简单键值对
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中如何增加自定义配置节”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!
分享标题:在web.config或者app.config中如何增加自定义配置节
标题来源:http://www.cdxtjz.cn/article/jehsss.html