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);