Can I add my own section to the web.config ?

  • Thread starter Thread starter craigkenisston
  • Start date Start date
C

craigkenisston

I need to store a few keys in the web.config file, so I was thinking to
add my own section like:

<MySection>
<MySection1 key1="blahblah" key2="asdf" />
<MySection2 key1="qwer" key2="zxcv" />
</MySection>

But wherever I place this, I get an error of "Unrecognized
configuration section".

Is it possible or not ?
 
I need to store a few keys in the web.config file, so I was thinking to
add my own section like:

<MySection>
<MySection1 key1="blahblah" key2="asdf" />
<MySection2 key1="qwer" key2="zxcv" />
</MySection>

But wherever I place this, I get an error of "Unrecognized
configuration section".

Is it possible or not ?

I don't think so...

What possible value would this add anyway? Store your keys in
<appSettings> - that's what it's for...
 
Sure can. You can create your own configuration sections and groups. Look at
the configSections element for the web.config file in the docs.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage
 
Ok, I get it.
Either I put everything inside the appSettings section, or I use the
configSettings sections to declare my own sections and then put
everything in there.

Thanks a lot !
 
Hi,

Mark said:
I don't think so...

Yes, it is. See Mark's reply in this thread.
What possible value would this add anyway? Store your keys in
<appSettings> - that's what it's for...

appSettings only allows key-value pairs. That's only sufficient for
limited settings. If you need something more solid, you need to define
your own schema.

HTH,
Laurent
 
re:
If you need something more solid, you need to define your own schema.

Maybe not quite as much as "define your own schema",
but you'd need to write your own configuration section handler.

See :
http://msdn2.microsoft.com/en-us/library/2tw134k3.aspx
....for ASP.NET 2.0

and:
http://msdn2.microsoft.com/en-us/library/ms228056.aspx
....for ASP.NET 1.1.

There's more examples and explanations, for 1.1, at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet04222003.asp




Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
 
Hi,
re:



Maybe not quite as much as "define your own schema",
but you'd need to write your own configuration section handler.

Maybe I expressed myself wrongly. What I meant is that you can add your
own config sections, including self-defined XML nodes, for example (from
the MSDN doc)

<myCustomGroup>
<myCustomSection myAttrib1="Clowns">
<myChildSection
myChildAttrib1="Zippy"
myChildAttrib2="Michael Zawondy "/>
</myCustomSection>
</myCustomGroup>

This is what I mean with "your own schema".

HTH,
Laurent
 
appSettings only allows key-value pairs. That's only sufficient for
limited settings. If you need something more solid, you need to define
your own schema.

Apologies, group - I didn't read the OP carefully enough...
 
Back
Top