Referencing external config files from Web.Config

Referencing external config files from Web.Config

Anybody programming with ASP.NET knows that you can store custom application’s settings in the web.config file, under the section, and programmatically read the values through the ConfigurationSettings class. When the application starts, the web.config is read and all its settings are cached, so that there isn’t a IO operation every time a value is needed. The web.config file is also automatically monitored for changes, and when a change is detected the file is read and cached again, but more importantly, the application is restarted and all the pages in the same directory and the subdirectories are recompiled on the next request, because the new settings of the web.config file might affect the page’s behavior (think about smart navigation, security, cookies and sessions, for example).

This means that if you frequently change the custom keys in the section, you’ll cause frequent recompilation of the pages, and thus slow down the application. You can easily avoid this problem, at least for custom application settings, by storing the settings in an external file referenced from web.config. This option, undocumented but present also in ASP.NET 1.0, allows you to change your custom settings without editing the web.config file, and thus avoid the application restart. The drawback is that if you actually want to reload the settings, you have to manually force an application restart, for example by making a fake change to web.config.

Let’s see how to put this tip in practice. Create a file named ExternalWeb.Config (you can use any name you want, but we suggest using the .config extension, so that the user can’t download and view it) with just the tag and its keys, as you would do in web.config:


Then, in web.config write the tag with the file attribute, that specifies the virtual path of the external configuration file written above. The settings stored in ExternalWeb.Config will be added to those defined in the web.config’s :


As a last note, if your external file has a key with the same name of a key defined in web.config, the key in the external value will override the value stored in web.config.

Note: This tip applies to Windows Forms’ configuration files too! (In VS.NET this file is named app.config, but after compilation it is copied to the bin folder as your_app_name_here.exe.config)

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as