views:

61

answers:

2

Does anyone have any good techniques for easily switching between development and live builds for asp.net mvc websites? Every time I make some changes I need to change to go through my web.config and comment out all my local stuff and uncomment all my remote settings. I also need to update the linq-to-sql dbml file to point to the right connection string.

This happens every time I make a change in a controller. After I upload the changes I then have to do the same process and get it back to development (local) mode.

Is there an automatic way to handle this, or at least one setting that can flag between the two?

Thanks

+1  A: 

a way I've done is to make two groups of configuration settings

<LiveSomeSetting>something</LiveSomeSetting>
<TestSomeSetting>anotherthing</TestSomeSetting>

Then in my class that reads configuration info, I'd check on something like the system environment / computer name and if applicable to the name of your LIVE machine look at the settings... otherwise the development.

if (System.Environment.MachineName.ToLower().StartsWith("devMachineName"))
   IsLive = "Test";
else
   IsLive = "Live";

Application["IsLive"] = IsLive;
SomeSetting = ConfigurationManager.AppSettings[IsLive + "SomeSetting"];
DRapp
How and when do you reference that class? Is this from the global.asa?
chobo
yes.. from the Global.asax during the application startup I look at the configuration settings and store into a "global" variable, but am sure you can store them elsewhere or in another object in your app.
DRapp
Is there any security risk in having global variables? Could someone grab connection strings and what not?
chobo
There's always a way to scan / hack... however, for those really wanting to get into a site, its tough to stop them.
DRapp
A: 

I use a simple technique that Scott Hanselman blogged in '97. It basically involves maintaining separate web.config files for each of you build types. Then there is a pre-build event which copies the correct web.config into place.

It does have the down side of having to maintain 2+ web.config files but once you're up and running it isn't really that big an issue.

Have a look here at the article:
Managing Multiple Configuration File Environments with Pre-Build Events

HTHs,
Charles

Charlino