如何获得的web.config的appSettings的配置节没有的NameValueCollection有的、如何获得、web、config

2023-09-03 16:08:20 作者:裤兜里没有糖

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

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

解决方案

 无功配置= WebConfigurationManager.OpenWebConfiguration(〜);
变种appSettingsSection =(AppSettingsSection)configuration.GetSection(的appSettings);
 

ConfigurationManager.AppSettings Property Returns a NameValueCollection object that contains the contents of the AppSettingsSection object for the current application's default configuration.

使用web.config设置伪静态的二种方法

but I need AppSettingsSection object because I need to change it configSource property in runtime

解决方案

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