Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add custom configuration section in web.config or app.config

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to add a custom configuration section in web.config or app.config. The article is very detailed and has certain reference value. Friends who are interested must read it!

Simple key-value pair

Web.config

Users.config

C#

NameValueCollection users = System.Configuration.ConfigurationManager.GetSection ("users") as NameValueCollection; Response.Write (users.Keys [0] + "+ users.Keys [1])

Complex type

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)

You can also define the configuration section as an entity

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 item0witi)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report