Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
Questions & Answers
Tips & Tricks
 How To use two Web.Config Files in Asp.Net Application?
Posted by Moderator1 on  3/27/2010 10:54:00 PM 6227 Views
This tip’s will help you to maintain two web.config files in an Asp.Net web application. The known factor is, by default, every web application will have single config file named as “Web.Config”. You can add keys and values under the <appSettings/> tag and retrieve it from the web application code-behind. For some additional purpose, the application can have more than one config file. But the application can recognize the file named as “Web.Config” or the only config file available in the application. So let us examine how we can make the application to retrieve the values from the second config file.

Step 1: In the Asp.Net web application, add the second web.config file named as “Web2.config”
Step 2: Remove all the default tags in Web2.Config file and add only <appSettings/> tag and its key-value as follows.
<add key="TestKey" value="Test Value From Web2.Config"/>
Step 3: In the default Web.Config file, at the <appSettings> tag, add an attribute as ‘file="Web2.config"’ as follows.
<appSettings file="Web2.config">
Step 4: Now access the value from the second config file as usual.

Post New Tips/Tricks View all Tips/Tricks

Featured Resources:
Sexy Web Design - Free 71 Page Preview!
An easy-to-follow guide that reveals the secrets of how to build your own breathtaking web interfaces from scratch.
Take Advantage of Oracle's 2 Day DBA Course
This course is designed to complement the Oracle 2 Day DBA documentation.
100% Free Subscription until Stock lost.View complete list.
Sponsored by