ConfigurationManager.AppSettings プロパティ 現在のアプリケーションのデフォルト構成の AppSettingsSection オブジェクトの内容を含む NameValueCollection オブジェクトを返します。
しかし、実行時にconfigSourceプロパティを変更する必要があるため、AppSettingsSectionオブジェクトが必要です
var configuration = WebConfigurationManager.OpenWebConfiguration("~");
var appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings");
AppSettingsSectionは、Configuration.GetSectionメソッドまたはConfiguration.AppSettingプロパティを使用して取得できます。
Configurationオブジェクトを取得するには、ConfigurationManager.Open...またはWebConfigurationManager.Open...メソッドを使用する必要があります。
string sectionName = "appSettings";
var config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection appSettingSection =
(AppSettingsSection)config .GetSection(sectionName);