c# - What is Difference between ConfigurationManager.GetSection and Configuration.GetSection? -


i'm trying create custom config file section based on appsettings:

<configsections>   <section name="customconfiguration"             type="system.configuration.appsettingssection,                   system.configuration,                   version=2.0.0.0, culture=neutral,                   publickeytoken=b03f5f7f11d50a3a"/> </configsections> 

when tried reading via configurationmanager.getsection("customconfiguration") object returned of type system.configuration.keyvalueinternalcollection. unable read values of collection, although see keys, , couldn't cast appsettingssection.

this stackoverflow answer suggests should use

configuration config =      configurationmanager.openexeconfiguration(configurationuserlevel.none); appsettingssection customsettingsection =      (appsettingssection)config.getsection("customconfiguration"); 

this worked. question is: difference between configurationmanager.getsection() , configuration.getsection()? when should use 1 , when should use other?

according msdn documentation on configuration class http://msdn.microsoft.com/en-us/library/system.configuration.configuration.aspx,

if application needs read-only access own configuration, recommended use getsection method overloads web applications. client application, use getsection method.

these methods provide access cached configuration values current application, has better performance configuration class.

specifically, in client applications, configurationmanager retrieves configuration file obtained merging application configuration file, local user configuration file, , roaming configuration file.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -