10

ConfigurationManager.AppSettings プロパティ 現在のアプリケーションのデフォルト構成の AppSettingsSection オブジェクトの内容を含む NameValueCollection オブジェクトを返します。

しかし、実行時にconfigSourceプロパティを変更する必要があるため、AppSettingsSectionオブジェクトが必要です

4

2 に答える 2

5
var configuration = WebConfigurationManager.OpenWebConfiguration("~");
var appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings");
于 2012-06-21T20:23:41.420 に答える
4

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);
于 2012-06-20T10:28:32.567 に答える