This tip explains how to keep application settings classified by sections in another config file.
Putting too much application setting in web.config in root may make it hard to read. So those can be kept in additional config file classified with sections.
Using the Code
A web.config file can be added in any folder other than root. If you only wish to store settings not specific to the folder you are adding it to, it is better to add it in a separate folder, as web.config in sub folder overrides settings from root.
Web.config in a sample project is as follows:
<add key="Setting1" value="value1" />
<add key="Setting2" value="value2" />
<add key="Setting1" value="value12" />
<add key="Setting2" value="value22" />
Here, I have added to sections,
Section2, of type
System.Configuration.NameValueSectionHandler to group
Group1. Configurations of the same are added below.
These settings can be read from code as shown below:
var Section1 =
(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath + "/MySettings"));
foreach (var key in Section1.AllKeys)
Response.Write("Key : " + key + " Value : " + Section1[key] + "<br/>");