Web.Config, Custom Section!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

    #1

    Web.Config, Custom Section!

    I'm trying to store something like this in my web.config file:

    <authInfoGrou p>
    <authInfo UserId="uid1" Passport="pwd1" Expiry="" />
    <authInfo UserId="uid2" Passport="pwd2" Expiry="" />
    </authInfoGroup>
    To do so, I've created the following section in my web.config:

    <configSections >
    <sectionGroup name="authInfoG roup">
    <section name="authInfo"
    type="System.Co nfiguration.Sin gleTagSectionHa ndler, System,
    Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9"/>
    </sectionGroup>
    </configSections>

    However, this fails and here's the error desc.:

    Sections must only appear once per config file. See the help topic
    <location> for exceptions

    However, I need to keep the above-mentioned data in my web.config file; and
    obviously, there are always more than one authInfo that I'm going to keep.

    Any idea?

    Thanks in advance,
    Mehdi


  • Scott M.

    #2
    Re: Web.Config, Custom Section!

    Change:
    [color=blue]
    > <authInfoGrou p>
    > <authInfo UserId="uid1" Passport="pwd1" Expiry="" />
    > <authInfo UserId="uid2" Passport="pwd2" Expiry="" />
    > </authInfoGroup>[/color]

    To:

    <appSettings>
    <add key="uid1" value="pwd1,"" />
    <add key="uid2" value="pwd2,"" />
    </appSettings>


    Then, to retrieve the values in another file:

    Dim UserInfo as string =
    System.Configur ation.Configura tionSettings.Ap pSettings("uid1 ")

    You could then use various string methods to parse the value for the
    password and/or expiration.



    <mehdi__mousavi @hotmail.com> wrote in message
    news:OI43DosvEH A.1292@TK2MSFTN GP10.phx.gbl...[color=blue]
    > I'm trying to store something like this in my web.config file:
    >
    > <authInfoGrou p>
    > <authInfo UserId="uid1" Passport="pwd1" Expiry="" />
    > <authInfo UserId="uid2" Passport="pwd2" Expiry="" />
    > </authInfoGroup>
    > To do so, I've created the following section in my web.config:
    >
    > <configSections >
    > <sectionGroup name="authInfoG roup">
    > <section name="authInfo"
    > type="System.Co nfiguration.Sin gleTagSectionHa ndler, System,
    > Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9"/>
    > </sectionGroup>
    > </configSections>
    >
    > However, this fails and here's the error desc.:
    >
    > Sections must only appear once per config file. See the help topic
    > <location> for exceptions
    >
    > However, I need to keep the above-mentioned data in my web.config file;
    > and
    > obviously, there are always more than one authInfo that I'm going to keep.
    >
    > Any idea?
    >
    > Thanks in advance,
    > Mehdi
    >
    >[/color]


    Comment

    • Guest's Avatar

      #3
      Re: Web.Config, Custom Section!

      This is the fast solution, but I need the one I described. Any idea?

      "Scott M." <s-mar@nospam.nosp am> wrote in message
      news:e##TWpvvEH A.1404@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Change:
      >[color=green]
      > > <authInfoGrou p>
      > > <authInfo UserId="uid1" Passport="pwd1" Expiry="" />
      > > <authInfo UserId="uid2" Passport="pwd2" Expiry="" />
      > > </authInfoGroup>[/color]
      >
      > To:
      >
      > <appSettings>
      > <add key="uid1" value="pwd1,"" />
      > <add key="uid2" value="pwd2,"" />
      > </appSettings>
      >
      >
      > Then, to retrieve the values in another file:
      >
      > Dim UserInfo as string =
      > System.Configur ation.Configura tionSettings.Ap pSettings("uid1 ")
      >
      > You could then use various string methods to parse the value for the
      > password and/or expiration.
      >
      >
      >
      > <mehdi__mousavi @hotmail.com> wrote in message
      > news:OI43DosvEH A.1292@TK2MSFTN GP10.phx.gbl...[color=green]
      > > I'm trying to store something like this in my web.config file:
      > >
      > > <authInfoGrou p>
      > > <authInfo UserId="uid1" Passport="pwd1" Expiry="" />
      > > <authInfo UserId="uid2" Passport="pwd2" Expiry="" />
      > > </authInfoGroup>
      > > To do so, I've created the following section in my web.config:
      > >
      > > <configSections >
      > > <sectionGroup name="authInfoG roup">
      > > <section name="authInfo"
      > > type="System.Co nfiguration.Sin gleTagSectionHa ndler, System,
      > > Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9"/>
      > > </sectionGroup>
      > > </configSections>
      > >
      > > However, this fails and here's the error desc.:
      > >
      > > Sections must only appear once per config file. See the help topic
      > > <location> for exceptions
      > >
      > > However, I need to keep the above-mentioned data in my web.config file;
      > > and
      > > obviously, there are always more than one authInfo that I'm going to[/color][/color]
      keep.[color=blue][color=green]
      > >
      > > Any idea?
      > >
      > > Thanks in advance,
      > > Mehdi
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Scott M.

        #4
        Re: Web.Config, Custom Section!

        I'm confused. Why do you "need" your solution, which doesn't work?

        What is it about what I've showed you that won't work for you?

        This is how you store user defined values in Web.Config and then retrieve
        them.


        <mehdi__mousavi @hotmail.com> wrote in message
        news:env9c7wvEH A.1204@TK2MSFTN GP10.phx.gbl...[color=blue]
        > This is the fast solution, but I need the one I described. Any idea?
        >
        > "Scott M." <s-mar@nospam.nosp am> wrote in message
        > news:e##TWpvvEH A.1404@TK2MSFTN GP11.phx.gbl...[color=green]
        >> Change:
        >>[color=darkred]
        >> > <authInfoGrou p>
        >> > <authInfo UserId="uid1" Passport="pwd1" Expiry="" />
        >> > <authInfo UserId="uid2" Passport="pwd2" Expiry="" />
        >> > </authInfoGroup>[/color]
        >>
        >> To:
        >>
        >> <appSettings>
        >> <add key="uid1" value="pwd1,"" />
        >> <add key="uid2" value="pwd2,"" />
        >> </appSettings>
        >>
        >>
        >> Then, to retrieve the values in another file:
        >>
        >> Dim UserInfo as string =
        >> System.Configur ation.Configura tionSettings.Ap pSettings("uid1 ")
        >>
        >> You could then use various string methods to parse the value for the
        >> password and/or expiration.
        >>
        >>
        >>
        >> <mehdi__mousavi @hotmail.com> wrote in message
        >> news:OI43DosvEH A.1292@TK2MSFTN GP10.phx.gbl...[color=darkred]
        >> > I'm trying to store something like this in my web.config file:
        >> >
        >> > <authInfoGrou p>
        >> > <authInfo UserId="uid1" Passport="pwd1" Expiry="" />
        >> > <authInfo UserId="uid2" Passport="pwd2" Expiry="" />
        >> > </authInfoGroup>
        >> > To do so, I've created the following section in my web.config:
        >> >
        >> > <configSections >
        >> > <sectionGroup name="authInfoG roup">
        >> > <section name="authInfo"
        >> > type="System.Co nfiguration.Sin gleTagSectionHa ndler, System,
        >> > Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9"/>
        >> > </sectionGroup>
        >> > </configSections>
        >> >
        >> > However, this fails and here's the error desc.:
        >> >
        >> > Sections must only appear once per config file. See the help topic
        >> > <location> for exceptions
        >> >
        >> > However, I need to keep the above-mentioned data in my web.config file;
        >> > and
        >> > obviously, there are always more than one authInfo that I'm going to[/color][/color]
        > keep.[color=green][color=darkred]
        >> >
        >> > Any idea?
        >> >
        >> > Thanks in advance,
        >> > Mehdi
        >> >
        >> >[/color]
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • MJ

          #5
          Re: Web.Config, Custom Section!

          Try

          <authInfoGrou p>
          <authInfos>
          <authInfo UserId="uid1" Passport="pwd1" Expiry="" />
          <authInfo UserId="uid2" Passport="pwd2" Expiry="" />
          </authInfos>
          </authInfoGroup>

          And

          <configSections >
          <sectionGroup name="authInfoG roup">
          <section name="authInfos "
          type="System.Co nfiguration.Sin gleTagSectionHa ndler, System,
          Version=1.0.500 0.0, Culture=neutral ,
          PublicKeyToken= b77a5c561934e08 9"/>
          </sectionGroup>
          </configSections>

          The code in your class that implements IConfigurationS ectionHandler
          should then be able to move through the XmlNode.ChildNo des
          collection inspecting each <authInfo>.

          Hope this helps.


          <mehdi__mousavi @hotmail.com> wrote in message news:<OI43DosvE HA.1292@TK2MSFT NGP10.phx.gbl>. ..[color=blue]
          > I'm trying to store something like this in my web.config file:
          >
          > <authInfoGrou p>
          > <authInfo UserId="uid1" Passport="pwd1" Expiry="" />
          > <authInfo UserId="uid2" Passport="pwd2" Expiry="" />
          > </authInfoGroup>
          > To do so, I've created the following section in my web.config:
          >
          > <configSections >
          > <sectionGroup name="authInfoG roup">
          > <section name="authInfo"
          > type="System.Co nfiguration.Sin gleTagSectionHa ndler, System,
          > Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9"/>
          > </sectionGroup>
          > </configSections>
          >
          > However, this fails and here's the error desc.:
          >
          > Sections must only appear once per config file. See the help topic
          > <location> for exceptions
          >
          > However, I need to keep the above-mentioned data in my web.config file; and
          > obviously, there are always more than one authInfo that I'm going to keep.
          >
          > Any idea?
          >
          > Thanks in advance,
          > Mehdi[/color]

          Comment

          • MJ

            #6
            Re: Web.Config, Custom Section!

            Missed the significance of SingleTagSectio nHandler and had thought
            your were writing your on implementation of
            IConfigurationS ectionHandler(w hich might be an idea?).

            But try this setup

            <?xml version="1.0" encoding="utf-8" ?>
            <configuratio n>
            <configSections >
            <section name="myCustomS ection"
            type="System.Co nfiguration.Sin gleTagHandler,
            System, Version=1.0.330 0.0, Culture=neutral ,
            PublicKeyToken= b77a5c561934e08 9" />
            </configSections>

            <myCustomSectio n mykey="myvalue" />
            </configuration>

            which comes from

            http://msdn.microsoft.com/library/de...et04222003.asp




            syadvada@hotmai l.com (MJ) wrote in message news:<6402b348. 0411010125.679b 7e54@posting.go ogle.com>...[color=blue]
            > Try
            >
            > <authInfoGrou p>
            > <authInfos>
            > <authInfo UserId="uid1" Passport="pwd1" Expiry="" />
            > <authInfo UserId="uid2" Passport="pwd2" Expiry="" />
            > </authInfos>
            > </authInfoGroup>
            >
            > And
            >
            > <configSections >
            > <sectionGroup name="authInfoG roup">
            > <section name="authInfos "
            > type="System.Co nfiguration.Sin gleTagSectionHa ndler, System,
            > Version=1.0.500 0.0, Culture=neutral ,
            > PublicKeyToken= b77a5c561934e08 9"/>
            > </sectionGroup>
            > </configSections>
            >
            > The code in your class that implements IConfigurationS ectionHandler
            > should then be able to move through the XmlNode.ChildNo des
            > collection inspecting each <authInfo>.
            >
            > Hope this helps.
            >
            >
            > <mehdi__mousavi @hotmail.com> wrote in message news:<OI43DosvE HA.1292@TK2MSFT NGP10.phx.gbl>. ..[color=green]
            > > I'm trying to store something like this in my web.config file:
            > >
            > > <authInfoGrou p>
            > > <authInfo UserId="uid1" Passport="pwd1" Expiry="" />
            > > <authInfo UserId="uid2" Passport="pwd2" Expiry="" />
            > > </authInfoGroup>
            > > To do so, I've created the following section in my web.config:
            > >
            > > <configSections >
            > > <sectionGroup name="authInfoG roup">
            > > <section name="authInfo"
            > > type="System.Co nfiguration.Sin gleTagSectionHa ndler, System,
            > > Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9"/>
            > > </sectionGroup>
            > > </configSections>
            > >
            > > However, this fails and here's the error desc.:
            > >
            > > Sections must only appear once per config file. See the help topic
            > > <location> for exceptions
            > >
            > > However, I need to keep the above-mentioned data in my web.config file; and
            > > obviously, there are always more than one authInfo that I'm going to keep.
            > >
            > > Any idea?
            > >
            > > Thanks in advance,
            > > Mehdi[/color][/color]

            Comment

            Working...