ConfigurationSettings.GetConfig

  • Thread starter Thread starter Mythran
  • Start date Start date
M

Mythran

[STAThread()]
public static void Main()
{
string sectionName = "system.web";
object settings = ConfigurationSettings.GetConfig(sectionName);
Console.WriteLine(
settings == null ? "(null)"
: settings.GetType().ToString()
);
}

I'm trying to access the system.web section in the machine.config file. I
thought that ConfigurationSettings.GetConfig would get the configuration
section that match the sectionName above, from all loaded configuration
files. When I run this, it always gives me null. So, how can I get the
"system.web" section of the machine.config file using ConfigurationSettings?
If I can't do it this way, and I have to do it by loading the machine.config
as an XmlDocument, then what is the best way to get the path to the
machine.config file? I know there are registry keys and I could use
Path.Combine to combine paths, but is there a property on an object that
gives at least part of the path information to the machine.config file?

Any help is appreciated :)

Thanks,
Mythran
 
I can tell you why it doesn’t work... but not how to get around it just yet.

ConfigurationSettings.GetConfig() is defined as: “Returns configuration
settings for a user-defined configuration section.†and system.web is not a
user defined configuration setting.

Give me a few on trying to find machine.config.

Brendan
 
Brendan Grant said:
I can tell you why it doesn’t work... but not how to get around it just
yet.

ConfigurationSettings.GetConfig() is defined as: “Returns configuration
settings for a user-defined configuration section.†and system.web is not
a
user defined configuration setting.

Give me a few on trying to find machine.config.

Brendan

How about 3½ hours? :P I know I can get it from the registry, so don't
destroy a brain cell trying to figure out other ways if you don't "need" to
:)

Thanks in any case ;)

Mythran
 
Back
Top