Click here to Skip to main content
15,884,237 members
Articles / Web Development / ASP.NET

Understanding Section Handlers - App.config File

Rate me:
Please Sign up or sign in to vote.
4.51/5 (56 votes)
15 Jul 20054 min read 616.5K   7K   165  
This article explains configuration section handlers defined in the System.Configuration namespace and explains how to create custom sections handlers by implemeting the IConfigurationSectionHandler interface.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
	
	<sectionGroup name="settings">
		<section name="dbSettings" type="System.Configuration.NameValueSectionHandler"/>
	</sectionGroup>
	
	<sectionGroup name="inputScreen">
		<section name="education" type="System.Configuration.DictionarySectionHandler"/>
		<section name="sex" type="System.Configuration.SingleTagSectionHandler"/>
	</sectionGroup>
	
	<sectionGroup name="companyInfo">
			<section name="companyAddress" type="ConfigSections.MyConfigHandler,ConfigSections"/>
	</sectionGroup>
	
</configSections>

<settings>
	<dbSettings>
		<add key="connectionString" value="Data Source=localhost;Initial Catalog=Northwind;"/>
		<add key="imagesPath" value="c:\MyApp\Resources\Images\"/>
	</dbSettings>
</settings>

<inputScreen>
	<education>
		<add key="1" value="High School"/>
		<add key="2" value="Bachelors"/>
		<add key="3" value="Masters"/>
		<add key="4" value="Doctorate"/>
	</education>
	
	<sex Male="1" Female="2"/>
</inputScreen>

<companyInfo> 
	<companyAddress> 
			 <companyName>Axxonet Solutions India Pvt Ltd</companyName>
			 <doorNo>1301</doorNo>
			 <street>13th Cross, Indira Nagar, 2nd Stage</street>
			 <city>Bangalore</city>
			 <postalCode>560038</postalCode>
			 <country>India</country>
	</companyAddress>
</companyInfo>

<!--
	Read appsettings from an external file.
-->
<appSettings file="appSettings.xml"/>
<appSettings>
	<add key="author" value="Palanisamy Veerasingam"/>
	<add key="article" value="Configuration Sections"/>
</appSettings>
</configuration>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions