473,471 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2649
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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.