We need to modify Web.config in two different areas; near the top, and near the bottom.
Listing 2 – Change the Top Area
<?xml version="1.0" encoding="utf-8" ?>
<configSections>
<section name="appReleaseSection" type="System.Configuration.NameValueFileSectionHandler,
System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</configSections>
Note that this code goes between the <configuration> opening tag and the <system.web> opening tag. You really do need all the gobbledy-gook in the type attribute. I’ve tried taking parts of it out, and it just stops working without it. Note that here we are referencing the NameValueFileSectionHandler alluded to earlier. There is a useful Microsoft reference on creating new configuration sections that you should take a moment to read. The most useful part of this reference is how to use the same configuration section handler that is used for the <appSettings> section. That is what we are doing here. The tag <section> above was merely lifted from similar code. The code sample in the link has some additional section tags that aren’t required, so I’ve eliminated them. You can also create your own IConfigurationSectionHandler object, but it’s just simpler to use one that already exists, particularly since our data is so simple.
If you are not familiar where to locate the Version, Culture, and PublicKeyToken values for the NameValueFileSectionHandler, all you have to do is look at the machine.config file on server.
The following code goes just below the closing </appSettings> or </system.web> depending on whether you have an <appSettings> section or not. In my example, we do.
Listing 3 – Change the Bottom Area
</appSettings>
<appReleaseSection file="Release.config">
</appReleaseSection>
Note that the file attribute is a relative path assignment. You can probably place your custom file lower down from the root, say in a special "config" directory if you want to be clever, but this suffices for the example.