views:

227

answers:

2

According to an earlier question about Visual Studio configurations, there's no way to use Visual Studio's configuration manager to create different configurations for an ASP.net web site project.

For normal projects, we have #if directives that switch certain server or database variables depending on whether we're debugging or in production. This doesn't work for web sites.

For example, in a class (in App_Code) that defines a web site's back-end server connection, there might be a chunk of code like this which overrides production values in the web.config if you want to run a debug server on your local machine:

#if DEBUGLOCAL
           ServerProperties.ServerIP = "localhost";
           ServerProperties.DataContextIP = "localhost";
#endif

This doesn't work, since there's no "Debug Local" configuration for the website, thus no DEBUGLOCAL defined.

Have you found a good way to work around problems like this? Besides (I hope) refactoring everything so all those references live in a class library project?

ETA: Can web deployment projects help here?

+1  A: 

Perhaps a Web Deployment project that does some swapping in the web.config may be of some help? Another thought would be to have a connection string in the web.config that pulls various values from a pre-specified database that can exist in each environment to allow for easy changes to the settings without needing to touch any files.

JB King
Darcy Casselman
Scott Gutherie's blog usually has the latest and greatest ASP.Net stuff and is where I heard of Web Deployment Projects. http://weblogs.asp.net/scottgu/ is a link to his blog, which now has lots of ASP.Net MVC and Silverlight stuff.
JB King
A: 

Another option may be to upgrade the web site to a web application.

That could be a lot of work to make the transition now, but the ability to have configurations may help tip the scales if you're deciding to go with a web site or web application.

Darcy Casselman