Accessing an attribute on a configSection in a web.config?
Solution: Just to add the solution: sectionGroups do not seem to have attributes. The proper way seems to have a
Original Question: I have a custom sectionGroup in my web.config:
The sectionGroup itself is supposed to have an attribute:
I have trouble accessing that attribute (defaultModule). Getting a section is very easy using
But I can’t seem to easily access the sectionGroup, as
Am I misunderstanding something? Are sectionGroups really only Containers with no settings of their own? Can I nest sections without having a sectionGroup at all? And is
Edit: Thanks for the hint regarding WebConfigurationManager instead of ConfigurationManager. That doesn’t solve my main problem, but at least this has more sensible named OpenXXX methods.
At the moment, these are the two classes. The LocaleSettings works perfectly fine, just the SectionHandler doesn’t let my access the “defaultModule” attribute.
Almost all you’re trying to do should be possible and should be ok and legal – you must be missing something small, I guess. The only thing I’m not sure of is whether section groups can have attributes of their own – they might be designed as being just containers for sections, which then have the actual config data in them…
For accessing the web.config, you should also try to use the
Can you show us the code for your
Have you checked out Jon Rista’s three-part series on .NET 2.0 configuration up on CodeProject? It’s an excellent intro to how to use and extend the .NET config system – highly recommended, and most useful indeed!
If you’re dealing with custom config sections, I would also recommend you have a look at the Configuration Section Designer, a Visual Studio plug-in that allows you to visually define your config section groups and config sections and the attributes and their datatypes in those sections – great time saver and educational tool!
Some more digging has shown: