asp.net - 如何获取 web.config appSettings 作为 ConfigurationSection 而不是 NameValueCollection

标签 asp.net .net

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

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

最佳答案

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

关于asp.net - 如何获取 web.config appSettings 作为 ConfigurationSection 而不是 NameValueCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11117560/

相关文章:

c# - 构建一个 C# 应用程序,使其根据运行的云使用 s3 或 blob

c# - FormsAuthentication.SetAuthCookie 在 IE9 或 Chrome 中不工作

c# - 如何使用属性过滤 Xml 文件?

c# - 在鼠标离开事件时关闭 ComboBox DropDown

.net - 在 opencv 中查找视频帧的熵时出现奇怪的输出

c# - Attribute.IsDefined 与 MemberInfo.IsDefined - 继承参数的区别

c# - 本地主机永远等待 ASP.NET 5 应用程序模板项目

asp.net - OWIN 和 Katana - 中间件到底是什么?

c# - X 返回结果后中继器拆分

c# - 为 BitArray 生成良好的哈希码 (GetHashCode)