Different configuration files on local vs. server.

M

Mufasa

How can you have different web.config files on your test machine vs.
production? I realize I could not include it in the project but the problem
is that if I make changes that go in both places I need to have them in both
places. But things like connect strings need to be different.

Can I have two config files and only include one of them in the project so
it get's published but the other one doesn't?

TIA - Jeff.
 
S

sloan

One Idea:

Push certain things out to external files:



<?xml version="1.0" encoding="utf-8" ?>
<configuration>


<appSettings file="CustomAppSettings.config" >
</appSettings>


<connectionStrings configSource="ExternalConnectionStrings.config" />


</configuration>

....................

AppSettings.config

<appSettings>


<add key="Key1" value="Value1"/>

</appSettings>


.............

ExternalConnectionStrings.config
<connectionStrings >


<add name="MyDatabaseInstance" connectionString="server=.;database=MYDB;User
ID=user1;password=password1" providerName="System.Data.SqlClient"/>

</connectionStrings>





Note, you'll have to use the POST BUILD EVENTS to get the files to copy in
(non web) projects.


Just right click / Add new item / app config (and then rename )
 
M

Mufasa

So if I have two config files and include them both in the project it will
find them both?

What happens if the same things are in both files?

TIA.
 
T

Tiberiu Covaci

Hi Mufasa,

There is a third option. Web.config might be found at different levels:
- Machine (C:\Windows\Micorsoft.Net\Framework\v???\config\web.config)
- Web site (Root_folder_of_your_web_site\Web.config)
- Your web application (web.config)
- Your subfolder in your application(another web.config)
If you want something to be available machine wide, you can just put it on
you machine web.conf, and then it wil propagate to your application. If you
want to change that value at a different level, just change it in that
place.

Regards,
Tibi
MCT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top