Working With More Than One Web.Config File
Sign in

Working with more than one Web.config file

Project Leader

Introduction

I would like to share what I have understood about working with more than one Web.config file from my latest ASP.NET application. It helps us to have small and easily maintainable configuration files.

Example:

The sample source code is a simple ASP.NET web application with three Web Forms and three Web.config files. The root folder has a sub folder SubFolder that has SubFolder2, each has one Web Form and one Web.config file.

Web.config files have different and overridden keys. Web.config file in the root folder has the following appSettings declarations:

<appSettings>
<add key="subfolder" value="Subfolder\web.config file."/>
<add key="color" value="Green"/>
</appSettings>

The color setting is overridden by the subfolder configuration file. We can read the root element from Subfolder or Subfolderby the following code:

lbl.Text = ConfigurationSettings.AppSettings["root"];

But we can not read configuration settings defined in Subfolder's Web.config file from the root folder.


start_blog_img