Posting Terbaru

Rabu, 09 Juli 2008

Move Settings Out of the Web.config File

Tidak ada komentar :
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:
... ...
To move that section to a separate file, simply replace the connectionStrings section in the listing above with this line:

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

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.
Source:ASP101

Tidak ada komentar :