Tag: 自定义配置

将web.config部分读取到List

我在web.config中有这个: 我想读取所有部分“MySection”并获取List所有值(例如:“10”,“20”,“30”) 谢谢,

自定义C#config无法识别的元素exception

我在App.config中有以下针对.NET 3.5 Windows服务的位: 我在configurationServiceSection.config中有这个: 这是代码: using System.Configuration; namespace SomeApp.Framework.Configuration { public sealed class ConfigurationServiceSection : ConfigurationSection { [ConfigurationProperty(“ConfigurationServices”, IsDefaultCollection = true, IsRequired = true)] [ConfigurationCollection(typeof(ConfigurationServices))] public ConfigurationServices ConfigurationServices { get { return (ConfigurationServices)base[“ConfigurationServices”]; } } } public sealed class ConfigurationServices : ConfigurationElementCollection { protected override ConfigurationElement CreateNewElement() { return new ConfigurationService(); } protected override object […]

App.config中的自定义配置部分C#

我是c#中配置部分的初学者 我想在配置文件中创建自定义部分。 我在google搜索后尝试的内容如下 配置文件: CustomSection.cs namespace CustomSectionTest { public class CustomSection : ConfigurationSection { [ConfigurationProperty(“key”, DefaultValue=”Default”, IsRequired = true)] [StringValidator(InvalidCharacters = “~!@#$%^&*()[]{}/;’\”|\\”, MinLength = 1, MaxLength = 60)] public String Key { get { return this[“key”].ToString(); } set { this[“key”] = value; } } } } 当我使用此代码检索Section时,我收到一条错误说配置错误。 var cf = (CustomSection)System.Configuration.ConfigurationManager.GetSection(“CustomSection”); 我错过了什么? 谢谢。 编辑 我最终需要的是