2012-06-20 12 views

Antwort

5
var configuration = WebConfigurationManager.OpenWebConfiguration("~"); 
var appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings"); 
3

Sie ändern muß die AppSettingsSection mit dem Configuration.GetSection Verfahren oder mit der Configuration.AppSetting Eigenschaft erhalten können.

Um ein Objekt Configuration Sie die ConfigurationManager.Open... oder die WebConfigurationManager.Open... Methoden verwenden müssen zu erhalten:

string sectionName = "appSettings"; 
var config = 
    ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
AppSettingsSection appSettingSection = 
    (AppSettingsSection)config .GetSection(sectionName); 
+2

Konnte nicht das Objekt des Typs ‚System.Configuration.KeyValueInternalCollection‘ werfen zu geben ‚System.Configuration.AppSettingsSection ". – Bohdan

+0

@Bohdan ja du hast Recht Ich habe meine Antwort aktualisiert. – nemesv

Verwandte Themen