4 Easy Steps to Custom Sections in web.config | Microsoft
Microsoft Blog

4 Easy Steps to Custom Sections in web.config

In a recent project, I used the web.config file to store some configuration settings that could easily be modified without redeploying code. I used the standard appSettings in <configurations><appSettings><add key=”” value=”” /> .  This works great when you have a specific key name and value. For one specific setting, I needed a little more flexibility.  I created a custom section in the web.config and the handler to read that section. Let me show you how.

Step 1

Define the xml markup needed by your custom section.  Think about all the options and attributes needed by each item. You can have required and optional attributes along with default values.

Step 2

Create the handler to read the custom xml.

Step 3

Declare the handler at the top of the web.config file.

Step 4

Use the data from the custom section in your code.

Complete web.config

Here is the complete web.config file for a more complete picture.


Subscribe to the Microsoft Weekly Digest

* indicates required

Leave a Reply

Perficient Microsoft Blog

Insights, best practices and technical perspectives to help you leverage your investment in Microsoft technology solutions to power your business growth