I have the following XML in my web.config
<mySectionGroup>
<sectionOneSection>
<page path="~/123.aspx"></page>
<page path="~/456.aspx"></page>
</sectionOneSection>
</mySectionGroup>
And the following code
public class SectionOneSection : ConfigurationSection {
[ConfigurationProperty("sectionOne")]
public PageConfigurationCollection Pages {
get {
return this["sectionOne"] as PageConfigurationCollection;
}
}
public static SectionOneSection GetConfig() {
return ConfigurationManager.GetSection("mySectionGroup/sectionOneSection") as
SectionOneSection;
}
}
public class PageElement : ConfigurationElement {
[ConfigurationProperty("path", IsRequired = true)]
public string Path {
get {
return this["path"].ToString();
}
set {
this["path"] = value;
}
}
}
public class PageConfigurationCollection : ConfigurationElementCollection {
public PageElement this[int index] {
get {
return base.BaseGet(index) as PageElement;
}
set {
if (base.BaseGet(index) != null) {
base.BaseRemoveAt(index);
}
this.BaseAdd(index, value);
}
}
protected override string ElementName {
get {
return base.ElementName;
}
}
protected override ConfigurationElement CreateNewElement() {
return new PageElement();
}
protected override object GetElementKey(ConfigurationElement element) {
return ((PageElement)element).Path;
}
}
And I get the following error when trying to retrieve that section
Unrecognized element 'page'. (C:\app\web.config line 39)
What am I missing here?