如何获得的web.config的appSettings的配置节没有的NameValueCollection [英] How to get web.config appSettings as ConfigurationSection not NameValueCollection

查看:142
本文介绍了如何获得的web.config的appSettings的配置节没有的NameValueCollection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

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

这篇关于如何获得的web.config的appSettings的配置节没有的NameValueCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆