1

I have several configuration entries for application. Identical entries are stored in Machine.config/Web.config etc.. How would I determine which one is read at run time..

2 Answers 2

1

You can use Configuration API to open machine configuration.

ContextInformation.IsMachineLevel is what you need. Configuration.EvaluationContext gives you the ContextInformation object and ElementInformation object gives you all the information including down to the source file path and the line number.

http://msdn.microsoft.com/en-us/library/system.configuration.configurationsection_properties.aspx

http://msdn.microsoft.com/en-us/library/system.configuration.contextinformation.ismachinelevel.aspx

http://msdn.microsoft.com/en-us/library/system.configuration.elementinformation_members.aspx

You can use OpenMachineConfiguration method to open particular configuration files. http://msdn.microsoft.com/en-us/library/ms228063.aspx

1

In general, Web.config settings in a folder inherits and can override settings from the Web.config files in parent folders, the application root Web.config file, and the machine.config file.

Consequently, settings in the closest Web.config file take precedence over the root Web.config file and the machine.config file. There's a catch though. You can't define all settings in all places. Some settings can only get defined at machine.config level. Some can be defined at the application root level but not in subfolders.

2
  • Question is How to determine which one of them(Machine.config/Web.config) is read at run time
    – TonyP
    Jan 31, 2010 at 11:13
  • 1
    From his answer, it seems that the most deeply nested web.config > less nested web.config > machine.config.
    – mbillard
    Jan 31, 2010 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.