In ASP.NET, when creating a custom config section, how do I limit the number of a particular section that can be declared?
For example, if in web.config, I repeat the appSettings section…
<appSettings />
<appSettings />
…I get an exception when the configuration loads.
If I do the same with my section…
<employer />
<employer />
…it allows it, but I don’t want it to.
My section code (C#) looks like this:
[ConfigurationProperty("employer", IsRequired = true)]
public EmployerElement Employer
{
get
{
return (EmployerElement)this["employer"];
}
set
{ this["employer"] = value; }
}
Any help appreciated, thanks.
I think each configuration property can only appear once in a section. I tested it in my code and I got an exception. The above code is only a property. Can you post the completed code of config section and
EmployerElementconfiguration element?