How. NET reads from defined nodes and issues that are noted in Web.config
Source: Internet
Author: User
web| problem these days in doing a urlmapping class library to use how to read the web.config in the custom node, finished feel very good now on the production process described.
Web.config files play a very important role in Web application. It itself contains a set of authorizations, handler,compilation,globalization, errors, and tracking. But what should you do when you need something special or want to add your own settings?
There are 2 steps required to create a custom setting: Write CS code and modify Web.config
Code
Here we create a simple handler that handler used in Web.config files.
Using System; Using System.Collections; Using System.Xml; Using System.Configuration; Using System.Web.Configuration; namespace Devhood {Internal class Pagestylehandler:iconfigurationsectionhandler {public virtual object Create (object pa Rent, Object context, XmlNode node) {pagestyle config = new Pagestyle ((Pagestyle) parent); config. Loadvaluesfromconfigurationxml (node); return config; } public class Pagestyle {string _backcolour; internal Pagestyle (pagestyle parent) {if (parent!= null) _backcolour = Parent._backcolour; } internal void Loadvaluesfromconfigurationxml (XmlNode node) {XmlAttributeCollection Attribcol = node. Attributes; _backcolour = attribcol["Backcolour"]. Value; public string Backcolour {get {return _backcolour}}} }
There are two classes: The Pagestylehandler class that inherits the IConfigurationSectionHandler interface and the Pagestyle class that is used to return data from Webconfig. The Pagestyle class can read an XML node (from Web.config) and hold the node data in the Backcolour attribute.
Setting up Web.config files
In order to be able to access Pagestylehandler, Web.config must be configured accordingly.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service