Hi, If you just want to do name/value collection, then why not use the <appsetting> tags, eg.
<system.web>
...
</system.web>
<!-- Generic application settings -->
<appSettings>
<add key="MyKey" value="MyValue" />
</appSettings>
Then use the following to access them:
System.Configuration.ConfigurationSettings.AppSettings["MyKey"]
But to answer your question about Custom config handlers, you need to create an object that implements the IConfigurationSectionHandler interface, e.g.
namespace MyCompany.MySystem.Web.MyProduct.Configuration.Custom
{
internal class CustomConfigHandler : IConfigurationSectionHandler
{
#region Custom Config Handler methods
public virtual object Create(Object parent, Object context, XmlNode node)
{
return new CustomConfig((CustomConfig)parent, node);
}
#endregion
}
public class CustomConfig
{
internal CustomConfig(CustomConfig parent, XmlNode node)
{
// implement how you want to parse the XML config
}
// methods/properties to access information
// ...
// ...
// ...
}
}
So the system calls our CustomConfigHandler object passing the XML contents of the config file, and it's up to us to parse this. I generally create an object (CustomConfig) that stores this XML and exposes methods/properties that the web application can call to get the details. The methods/properties simply perform SelectSingleNode(XPATH) on the stored XML to retrieve the details. This allows for a more complex config structure than simple name/value pairs, e.g. Here is a snippet of one of my custom config sections...
<!-- Custom application configuration -->
<osi.search.types>
<Type name="VIF">
< Provider type='CSV'>
<Source>
<!--
[Location] can be either a filename or
@fieldname, we the location will be determined
from the value of the @fieldname supplied with
the search
-->
<Location><![CDATA[@SearchLocalityName]]></Location>
<Base><![CDATA[C:\\CSVs\\]]></Base>
<SearchLocalityName>
<!-- United Kingdom -->
<Name value='AA01'>AA01.txt</Name>
<Name value='United Kingdom'>AA01.txt</Name>
<Name value='UK'>AA01.txt</Name>
</SearchLocalityN