ASP 101 - Active Server Pages 101 - Web04
The Place ASP Developers Go!

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

Exporting HTML from Word
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

Move Settings Out of the Web.config File

Did you know that you can move sections of your Web.config file into other files? Whether it's to keep things tidy or simply to make it easier to find the settings you change often, it's easy to do and yet few people even realize you can.

The magic that makes this possible is the configSource attribute. It was added in .NET 2.0 and its value indicates the name of the file that contains the section that we're moving to another file. It's probably easiest to illustrate via a simple example. A normal connectionStrings section in Web.config might look something like this:

<?xml version="1.0"?>
        <add name="SampleConnection" connectionString="..." />

To move that section to a separate file, simply replace the connectionStrings section in the listing above with this line:

<connectionStrings configSource="ConnectionStrings.config" />

and then create a new "ConnectionStrings.config" file to hold the connectionStrings section's settings:

<?xml version="1.0"?>
    <add name="SampleConnection" connectionString="..." />

See... it really couldn't be much simpler. Now you can play with your connection strings as much as you want without fear of messing up any other settings in your Web.config file.

Oh... and just because I only showed you how to move the connectionStrings section, don't think that it stops there. You can just as easily move any section you want to an external file: appSettings, mailSettings, urlMappings, etc.

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers