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

Discussion in 'ASP .Net' started by craigkenisston@hotmail.com, Sep 23, 2006.

  1. Guest

    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 ?
    , Sep 23, 2006
    #1
    1. Advertising

  2. Mark Rae Guest

    <> wrote in message
    news:...

    >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...
    Mark Rae, Sep 23, 2006
    #2
    1. Advertising

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

    <> wrote in message
    news:...
    >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 ?
    >
    Mark Fitzpatrick, Sep 23, 2006
    #3
  4. Guest

    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 !
    , Sep 24, 2006
    #4
  5. Hi,

    Mark Rae wrote:
    > <> wrote in message
    > news:...
    >
    >
    >>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...


    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
    --
    Laurent Bugnion, GalaSoft
    Software engineering: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch
    Laurent Bugnion, Sep 24, 2006
    #5
  6. 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/
    ===================================
    "Laurent Bugnion" <> wrote in message
    news:...
    > Hi,
    >
    > Mark Rae wrote:
    >> <> wrote in message
    >> news:...
    >>
    >>
    >>>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...

    >
    > 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
    > --
    > Laurent Bugnion, GalaSoft
    > Software engineering: http://www.galasoft-LB.ch
    > PhotoAlbum: http://www.galasoft-LB.ch/pictures
    > Support children in Calcutta: http://www.calcutta-espoir.ch
    Juan T. Llibre, Sep 24, 2006
    #6
  7. Hi,

    Juan T. Llibre wrote:
    > 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.


    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

    > 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

    --
    Laurent Bugnion, GalaSoft
    Software engineering: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch
    Laurent Bugnion, Sep 24, 2006
    #7
  8. Mark Rae Guest

    "Laurent Bugnion" <> wrote in message
    news:...

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


    Apologies, group - I didn't read the OP carefully enough...
    Mark Rae, Sep 24, 2006
    #8
  9. 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.

    ;-)



    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/
    ===================================
    "Laurent Bugnion" <> wrote in message
    news:...
    > Hi,
    >
    > Juan T. Llibre wrote:
    >> 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.

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

    > --
    > Laurent Bugnion, GalaSoft
    > Software engineering: http://www.galasoft-LB.ch
    > PhotoAlbum: http://www.galasoft-LB.ch/pictures
    > Support children in Calcutta: http://www.calcutta-espoir.ch
    Juan T. Llibre, Sep 24, 2006
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jared Hagel
    Replies:
    2
    Views:
    3,287
    Jared Hagel
    Apr 7, 2005
  2. clintonG
    Replies:
    4
    Views:
    345
    clintonG
    Aug 24, 2006
  3. Brian McCullough
    Replies:
    0
    Views:
    476
    Brian McCullough
    Feb 16, 2007
  4. CSharpner
    Replies:
    0
    Views:
    975
    CSharpner
    Apr 9, 2007
  5. kampy
    Replies:
    9
    Views:
    305
    Steven D'Aprano
    Oct 19, 2012
Loading...

Share This Page