<appsettings>

  • Thread starter Thread starter Kenneth
  • Start date Start date
K

Kenneth

Hi,

In web.config I have an appsettings:

<appSettings>
<add key="constring"
value="Server=localhost;UID=sa;PWD=secret;Database=myDB" />
</appSettings>

This is for my developing machine.

Every time I deploy this web.config to the production
server I forget to change the UID and PWD which are
different on this machine.

Is there a way to write some code that detects which
server you're on so the server picks the right UID and PW`?

/Kenneth
 
Of course you can't put running code into the web.config. That wasn't what I
mentioned.

Point really was that you'd put machinenames into <appSettings> as keys (or
as part of keys say "connectionString_MACHINENAME") for connection strings
and then by using Environment.MachineName your code solves in which machine
it is running and picks the correct config setting ("connectionString_" &
Environment.MachineName)

--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

AspInsiders Member, www.aspinsiders.com
ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com


"Kenneth" <[email protected]> kirjoitti viestissä
Kiitos paljon Teemu for a fast reply,

Environment.MachineName can't be used in web.config, only
in code in aspx doc.

If you have to test new things in web.config and test it
in dev machine then you'll end upp with a mess if you have
to rewrite it.

/Kenneth
 
Kenneth said:
Hi,

In web.config I have an appsettings:

<appSettings>
<add key="constring"
value="Server=localhost;UID=sa;PWD=secret;Database=myDB" />
</appSettings>

Kenneth,

You can do the following in web.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings file="user.config">
<add key="Key" value="Value" />
</appSettings>
</configuration>

Then, in a file called user.config in the same folder as web.config, you can
put the following (notice there's no "<configuration>" tag):

<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
<add key="Key" value="Override value" />
</appSettings>

If there is no user.config in the same folder, then the web.config settings
are used.
 
Back
Top