[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Conditional Web Config File in Asp.nET 2.0

Posted on 2007-03-19
7
Medium Priority
?
1,327 Views
Last Modified: 2013-11-07
Is it possible within the web.config under asp.net 2.0 to have conditional statements within the web.config file.

So that if the file is in dev/qa/prod it will know which settings to use for the various environments?

0
Comment
Question by:JDEE8297
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 27

Assisted Solution

by:Sammy Ageil
Sammy Ageil earned 400 total points
ID: 18752916
Nope thats not possible but you can change the web.config file using code behind.
0
 

Author Comment

by:JDEE8297
ID: 18752984
to change the web.config file using code behind your web user would have to read/write access to the file. Is that good practice to do that to a production app?. Not questioning your solution, just want to make sure I understand what is possible in this scenario.
0
 
LVL 15

Expert Comment

by:crisco96
ID: 18755215
If you want to be able to have pretty much the same web.config accross all applications you could do the following:

<add key="Environment" value="Dev" />

<!-- DEV variables -->
<add key="DevConn" value="Dev Database connection string" />
...

<!-- QA variables -->
<add key="QAConn" value="QA database connection string" />
...

<!-- Prod variables -->
<add key="ProdConn" value="Production database connection string" />
...

So now you could just change Environment to be Dev, QA or Prod and whenever you need to reference the connection string you could use:

ConfigurationSettings.AppSettings[ConfigurationSettings.AppSettings["Environment"] + "Conn"];

Setting up your web.config in this way may be easier for you.


I wouldn't recommend dynamically changing your web.config with code because each time you modify the web.config your application restarts killing everyone's sessions.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:JDEE8297
ID: 18755476
Crisco96

I like your approach, so I was wondering if it would be possible to split it into sections, as in have a new section within the web config and then based on the environment value I would pull from that section from the web config. I seem to remember reading something about custom sections in the web config and was wondering what your thoughts were on it.
0
 
LVL 15

Accepted Solution

by:
crisco96 earned 600 total points
ID: 18755505
It seems like you're thinking about the configSource tag which allows you to specify a different config file to pull appsettings or connectionstrings from.  

You can read more about it here: http://aspalliance.com/820

I don't know if using this would be any better than just having different web.configs for dev, qa or production, it just changes it so they are pulled from another config rather than the base web.config.
0
 

Author Comment

by:JDEE8297
ID: 18755572
true, but the problem is that no matter how much one places in the honour system, someone will always push the wrong config file to the wrong environment and hey presto the site will either go down or not display the correct information.

And the funny thing is that this will be up on the site for a week or so before anyone notices it, funny how that goes...:)
0
 

Author Comment

by:JDEE8297
ID: 18755578
Thank you for help on this one, gave me some ideas on how to set this up.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question