Why have machine.config and the application config file?
machine.config has default settings for all applications on your machine, and the application configuration file has settings just for the application. The application settings override the settings in
The technical explanation requires looking at the
Create method of
IConfigurationSectionHandler. This method is implemented by all configuration section handlers and looks like this:
object Create(object parent, object configContext, XmlNode section);
section parameter is the XML for that section, the
configContext parameter is only relevant to ASP.NET and will be ignored here.
GetConfig will call this twice: once for the section in
machine.config and then once more for the section in the application config file. The handler should process the XML and use this information to create a configuration object which is returned from
Create. If the call to
machine.config returns a configuration object, then this object is passed as the
parent parameter to the subsequent call to
Create for the application config file. It's entirely up to the handler to determine what it must do with this parent object, but clearly the most logical thing to do is to use the values as default values and if there are equivalent values in the application configuration file, then the parent values will be overwritten.