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



Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
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

QUICK TIP:
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"?>
<configuration>
    ...
    <connectionStrings>
        <add name="SampleConnection" connectionString="..." />
    </connectionStrings>
    ...
</configuration>

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"?>
<connectionStrings>
    <add name="SampleConnection" connectionString="..." />
</connectionStrings>

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: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

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