By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,727 Members | 757 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,727 IT Pros & Developers. It's quick & easy.

Different web.config's for development and production

P: n/a
Hi!

I have a pretty traditional setup where I develop on my local PC and the use
"Copy Project" to deploy to the production enviroment.. In web.config I need
different values for connectionstrings etc for development and production -
pretty normalt stuff.

Currently I edit the web.config manually before deploying, and have never
forgotten - but I know it is a matter of time before I or a colleague do.

I know this is a pretty common challenge, so I know there must be an easy
solution. In my search for this solution, I found something called
Configuration Override File. This seems to be what I am looking for - or? It
does not mention whether this is for the "copy project"-function or some
other deployment method I am not aware of. I have not been able to find more
info on this subject - so I turn to you, ladies and gentlemen! :)

How do I keep two different web.config's for development and production? And
deply the correct web.config in the right case without me having to change
anything manually - using the "Copy Project"-function?

Thanks in advance :)

- Klaus Jensen
Nov 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Yes, this is what you need, at this link you'll find e very nice guide with
all the infos you need:
http://www.microsoft.com/italy/net/b...ycle_guide.pdf

HtH,
Andrea

"Klaus Jensen" <CurseThemNastySpammers!> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
Hi!

I have a pretty traditional setup where I develop on my local PC and the use "Copy Project" to deploy to the production enviroment.. In web.config I need different values for connectionstrings etc for development and production - pretty normalt stuff.

Currently I edit the web.config manually before deploying, and have never
forgotten - but I know it is a matter of time before I or a colleague do.

I know this is a pretty common challenge, so I know there must be an easy
solution. In my search for this solution, I found something called
Configuration Override File. This seems to be what I am looking for - or? It does not mention whether this is for the "copy project"-function or some
other deployment method I am not aware of. I have not been able to find more info on this subject - so I turn to you, ladies and gentlemen! :)

How do I keep two different web.config's for development and production? And deply the correct web.config in the right case without me having to change
anything manually - using the "Copy Project"-function?

Thanks in advance :)

- Klaus Jensen

Nov 18 '05 #2

P: n/a
We use a session variable set in the global.asax like:
If Server.MachineName = "DevelopmentServer" Then
Session("Develop") = True
Else Session("Develop") = False

In your code you can then use this to read the correct
connection settings from web.config
-----Original Message-----
Hi!

I have a pretty traditional setup where I develop on my local PC and the use"Copy Project" to deploy to the production enviroment.. In web.config I needdifferent values for connectionstrings etc for development and production -pretty normalt stuff.

Currently I edit the web.config manually before deploying, and have neverforgotten - but I know it is a matter of time before I or a colleague do.
I know this is a pretty common challenge, so I know there must be an easysolution. In my search for this solution, I found something calledConfiguration Override File. This seems to be what I am looking for - or? Itdoes not mention whether this is for the "copy project"- function or someother deployment method I am not aware of. I have not been able to find moreinfo on this subject - so I turn to you, ladies and gentlemen! :)
How do I keep two different web.config's for development and production? Anddeply the correct web.config in the right case without me having to changeanything manually - using the "Copy Project"-function?

Thanks in advance :)

- Klaus Jensen
.

Nov 18 '05 #3

P: n/a
Howdy,

My approach was to create a custom configuration class, though the problem
with this is, that you need to create an instance of the class to access the
variables.
Web.config is modified as follows:
<!-- Define our custom section names -->
<configSections>
<sectionGroup name="settings">
<section name="development"
type="System.Configuration.NameValueFileSectionHan dler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<section name="production"
type="System.Configuration.NameValueFileSectionHan dler, System,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</sectionGroup>
</configSections>
<!-- Define development and production server settings for our
application -->
<settings>
<development>
<add key="server" value="127.0.0.1" />
<add key="mailserver" value="devmailserver" />
<add key="connstring" value="devconstring" />
</development>
<production>
<add key="server" value="liveIP_notused" />
<add key="mailserver" value="livemailserver" />
<add key="connstring" value="liveconstring" />
</production>
</settings>
A custom configuration class is used to access these variables. When
instantiated, this class checks which server the files are on, and pulls the
value from the appropriate group:
/// <summary>
/// Configuration Class
/// Check if we're using the development or live server, and get the
correct settings from web config
/// </summary>
public class CustomConfigClass
{
// Declare private variables
private bool _isDev = false;
private string _strThisServer =
HttpContext.Current.Request.ServerVariables["local_addr"];
private string _strDevServer;
private string _strProductionServer;

// Settings groups
private System.Collections.Specialized.NameValueCollection DevSettings;
private System.Collections.Specialized.NameValueCollection
ProductionSettings;
public CustomConfigClass()
{
// Get this server IP address
_strThisServer =
HttpContext.Current.Request.ServerVariables["local_addr"];

// Get the development and production server settings
DevSettings = (System.Collections.Specialized.NameValueCollectio n)
System.Configuration.ConfigurationSettings.GetConf ig("settings/development")
;
ProductionSettings = (System.Collections.Specialized.NameValueCollectio n)
System.Configuration.ConfigurationSettings.GetConf ig("settings/production");

// Get the development server IP
_strDevServer = DevSettings["server"];

// Get the production server IP
_strProductionServer = ProductionSettings["server"];

_isDev = (_strDevServer.IndexOf(_strThisServer) != -1);
}

/// <summary>
/// Get a value from web config
/// </summary>
/// <param name="pKey">Key</param>
/// <returns>string</returns>
public string Get(string pKey)
{
string strReturn;
if (this.IsDevServer)
{
strReturn = DevSettings[pKey];
}
else
{
strReturn = ProductionSettings[pKey];
}
return strReturn;
}
/// <summary>
/// This server's IP address
/// </summary>
public string ThisServer
{
get
{
return _strThisServer;
}
}
/// <summary>
/// Is development server
/// </summary>
public bool IsDevServer
{
get
{
return _isDev;
}
}
/// <summary>
/// Development server IP address
/// </summary>
public string DevServer
{
get
{
return _strDevServer;
}
}
/// <summary>
/// Production server IP address
/// </summary>
public string ProductionServer
{
get
{
return _strProductionServer;
}
}
}
It works quite well, though it's a bit of a hassle having to instantiate the
custom configuration class to access the settings. One of these days, I'll
re-write it to use static methods :-)

Hope this helps,

Mun

"Klaus Jensen" <CurseThemNastySpammers!> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
Hi!

I have a pretty traditional setup where I develop on my local PC and the use "Copy Project" to deploy to the production enviroment.. In web.config I need different values for connectionstrings etc for development and production - pretty normalt stuff.

Currently I edit the web.config manually before deploying, and have never
forgotten - but I know it is a matter of time before I or a colleague do.

I know this is a pretty common challenge, so I know there must be an easy
solution. In my search for this solution, I found something called
Configuration Override File. This seems to be what I am looking for - or? It does not mention whether this is for the "copy project"-function or some
other deployment method I am not aware of. I have not been able to find more info on this subject - so I turn to you, ladies and gentlemen! :)

How do I keep two different web.config's for development and production? And deply the correct web.config in the right case without me having to change
anything manually - using the "Copy Project"-function?

Thanks in advance :)

- Klaus Jensen


Nov 18 '05 #4

P: n/a
"Klaus Jensen" <CurseThemNastySpammers!> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
How do I keep two different web.config's for development and production? And deply the correct web.config in the right case without me having to change
anything manually - using the "Copy Project"-function?


Come on! Somebody else but me must have faced this challenge! :)

- Klaus
Nov 18 '05 #5

P: n/a
Yes.
We keep different setting in machine.config on development and production.
"Klaus Jensen" <CurseThemNastySpammers!> wrote in message news:%2****************@tk2msftngp13.phx.gbl...
"Klaus Jensen" <CurseThemNastySpammers!> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
How do I keep two different web.config's for development and production?

And
deply the correct web.config in the right case without me having to change
anything manually - using the "Copy Project"-function?


Come on! Somebody else but me must have faced this challenge! :)

- Klaus

Nov 18 '05 #6

P: n/a
"Klaus Jensen" <CurseThemNastySpammers!> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Klaus Jensen" <CurseThemNastySpammers!> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
How do I keep two different web.config's for development and production?

And
deply the correct web.config in the right case without me having to change anything manually - using the "Copy Project"-function?


Come on! Somebody else but me must have faced this challenge! :)


I use user.config for <appSettings> and maintain web.config at the
production configuration. I make few changes in the Development environment,
so I just make those by hand.
--
John Saunders
John.Saunders at SurfControl.com
Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.