472,989 Members | 3,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

Different web.config's for development and production

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
6 2614
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
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
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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Marty McDonald | last post by:
Many of an app's classes could read the config file. The config file could contain many elements, and it will be difficult to know which config file entry belongs to which class. I could adopt a...
5
by: sql-db2-dba | last post by:
We have DB2 UDB v8.1 fixpak3 on AIX 5. Production and Development configuarations (at least for DB2) are identical albeit production is a 2-way server while development has only one processor....
4
by: Benne Smith | last post by:
In our company, i have three servers; 1) a development server (mine only - here i make daily changes and test my stuff) 2) a test server (for the users to test milestone builds - changes weekly)...
0
by: Andy | last post by:
Hi all, I'd like to have an App.config file for development, then when I build the deployment package (using one of the VS.net projects), i'd like to specify a different .config file to install...
2
by: sqlster | last post by:
We have 3 different environments: dev, qa, and production. After unit testing, the application is deployed to dev for unit testing among the programmers and business analyst. When that is okay it...
8
by: Graham | last post by:
I noticed a similar post awhile ago and in terms of my problem it wasnt a suitable answer so I will ask again. I have VS2005 running a on development machine in my office where I do all my...
6
by: Joel H | last post by:
We have several settings in web.config that are different on the developer side than the production side. Our website sourcecode is under sourcesafe control, so before we code, we check out the...
2
by: SalamElias | last post by:
Hi, I am confornted with a problem regarding web.config file. I have 4 environements (Dev, Test, staging and production). The IT people need wgenever a new MSI delivered to have the right...
3
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi all, I am working on a windows forms app. I do my development in a development environment, and I have certain settings in my app.config like connection to WCF services that point to my...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.