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

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 ?
 
M

Mark Rae

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...
 
M

Mark Fitzpatrick

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
 
C

craigkenisston

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 !
 
L

Laurent Bugnion

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
 
J

Juan T. Llibre

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
 
L

Laurent Bugnion

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
 
M

Mark Rae

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...
 
J

Juan T. Llibre

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

heh, heh...

I knew you meant that.

Just wanted to make sure readers didn't take the word "schema" literally,
plus, also, point to documentation where instructions can be found.

;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top