Reading Web.Config
-
-
Hi, I want to create a class library that will read certain sections of my web.config, not just in the configuration section, how can I do this without doing the cheap and nastly way, reading the whole web.config into an xml dom and parsing. Thanks, Gerry.
Gerry wrote: how can I do this without doing the cheap and nastly way, reading the whole web.config into an xml dom and parsing. First you return a
NameValueCollection
of your custom config section;NameValueCollection config = (NameValueCollection) ConfigurationSettings.GetConfig("mygroup/nestedgroup/mysection");
Then you access theNameValueCollection
like so;config["key_one"]
It is all in MSDNPaul Watson
Bluegrass
Cape Town, South AfricaShog9 wrote: Everybody just wants to be naked and famous, Paul.
-
Gerry wrote: how can I do this without doing the cheap and nastly way, reading the whole web.config into an xml dom and parsing. First you return a
NameValueCollection
of your custom config section;NameValueCollection config = (NameValueCollection) ConfigurationSettings.GetConfig("mygroup/nestedgroup/mysection");
Then you access theNameValueCollection
like so;config["key_one"]
It is all in MSDNPaul Watson
Bluegrass
Cape Town, South AfricaShog9 wrote: Everybody just wants to be naked and famous, Paul.
-
That's fine but it's not in the configuration section. Example: I want to read the name and path attributes of the forms element. Gerry.
Gerry wrote: I want to read the name and path attributes of the forms element. Ahhh ok. If you are wanting a more general way of accessing any value in the web.config then yes, you probably have to use the Xml classes to get at it.
Paul Watson
Bluegrass
Cape Town, South AfricaShog9 wrote: Everybody just wants to be naked and famous, Paul.