How to create custom config sections in web.config file?
Step 1: Declare section group
<?xml version="1.0"?>
<configuration>
<!-- Definition of config file sections -->
<configSections>
<!-- define your custom section here -->
<section name="proxies" type="System.Configuration.NameValueSectionHandler,
System, Version=1.0.3300.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089"/>
<!-- System.Configuration.NameValueSectionHandler,
System, Version=1.0.5000.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 -->
</configSections>
</configuration>
Step 2: Declare own values in web.config
<?xml version="1.0"?>
<configuration>
<!-- Know to the system Proxy classes for remote Lines connections -->
<proxies>
<add key="LOCAL" value="Artfulbits.Proxy.LocalProxyAdapter"/>
<add key="AB-REMOTE" value="Artfulbits.Proxy.AbRemoteProxyAdapter"/>
</proxies>
</configuration>
Step 3: How to access defined values in web.config from ASP.NET code?
/// <summary></summary>
/// <returns></returns>
public static NameValueCollection GetProxiesDictionary()
{
return ConfigurationManager.GetSection( "proxies" ) as NameValueCollection;
}
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5