Alex Rivera | Logout

static value in web.config

Asked 2011-05-10T11:10:00.767
10

I have a project running on 2 servers. 1 testserver with a connection to a testDB, and one on the real server, with real DB.

The only different thing in each of the running instances of this project is the web.config.

What i'd like to do is have the possibility to set a value in web.config, a bool, which then could be read by the code. This bool would be true if the app is in testing mode. i'd set it manually, the project then would read it out, and when it's true, the mails the app would send, then would be kept internal, so people dont actually get mail. I did this before with setting a public static bool in global.asax but in Asp.net MVC everything is built into one DLL, so i cant change it on the deployed server in that case.

Is this possible? or would there be a nice other solution?

Edit
Report

1 Answer

0

If you are using Visual Studio 2010 I would recommend using Transformation files to transform the web.config. The more differences you have the more this will help you.

The high level steps:

  1. Create a new build configuration through configuration manager
  2. Set the values appropriately in each newly created config file
  3. Build and publish
  4. Done and never have to remember to change values in multiple config files (development, staging, release etc).

http://msdn.microsoft.com/en-us/library/dd465318.aspx

answered 2011-05-10T11:37:38.430

Your Answer