如何将web.config appSettings作为ConfigurationSection而不是NameValueCollection

Boh*_*dan 10 .net asp.net

ConfigurationManager.AppSettings属性返回NameValueCollection对象,该对象包含当前应用程序的默认配置的AppSettingsSection对象的内容.

但我需要AppSettingsSection对象,因为我需要在运行时更改它的configSource属性

Boh*_*dan 5

var configuration = WebConfigurationManager.OpenWebConfiguration("~");
var appSettingsSection = (AppSettingsSection)configuration.GetSection("appSettings");
Run Code Online (Sandbox Code Playgroud)