get/set data web.config

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Devlon

    get/set data web.config

    Hi

    Does anyone have the correct syntax to get and set the system settings in
    the web.config file ?

    I would like to read and change the smtp server, login, password and from
    adress....

    thanx

    John




  • Mark Rae [MVP]

    #2
    Re: get/set data web.config

    "John Devlon" <Johndevlon@hot mail.comwrote in message
    news:qa2Oj.1765 2$_h7.2374@news fe05.ams2...
    Does anyone have the correct syntax to get and set the system settings in
    the web.config file ?
    Provides access to configuration files for client applications. This class cannot be inherited.

    I would like to read and change the smtp server, login, password and from
    adress....
    Be aware that any changes to web.config while the web app is running will
    cause it to recycle, thereby tearing down all currently active sessions...


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • John Devlon

      #3
      Re: get/set data web.config

      Thanx Mark,

      I didn't know that.... Better to store the data somewhere else then....

      John



      "Mark Rae [MVP]" <mark@markNOSPA Mrae.netschreef in bericht
      news:eMaEjEWoIH A.5016@TK2MSFTN GP02.phx.gbl...
      "John Devlon" <Johndevlon@hot mail.comwrote in message
      news:qa2Oj.1765 2$_h7.2374@news fe05.ams2...
      >
      >Does anyone have the correct syntax to get and set the system settings in
      >the web.config file ?
      >
      Provides access to configuration files for client applications. This class cannot be inherited.

      >
      >I would like to read and change the smtp server, login, password and from
      >adress....
      >
      Be aware that any changes to web.config while the web app is running will
      cause it to recycle, thereby tearing down all currently active sessions...
      >
      >
      --
      Mark Rae
      ASP.NET MVP
      http://www.markrae.net

      Comment

      • Cowboy \(Gregory A. Beamer\)

        #4
        Re: get/set data web.config

        Very much so.

        In addition, it can be impossible to update web.config from your app
        (definitely in 1.x), as the app locks the file. Unless you are truly working
        with configuration elements, I would store in an XML file or a database.

        In .NET 2.0, you can specify additional configs, that you can alter while
        the site is running, if these truly are "dynamic" config elements, but I
        would consider metadata tables in a database first.

        --
        Gregory A. Beamer
        MVP, MCP: +I, SE, SD, DBA

        Subscribe to my blog


        or just read it:


        *************** *************** *************** ****
        | Think outside the box!
        |
        *************** *************** *************** ****
        "John Devlon" <Johndevlon@hot mail.comwrote in message
        news:mv2Oj.5683 2$Lq5.25405@new sfe18.ams2...
        Thanx Mark,
        >
        I didn't know that.... Better to store the data somewhere else then....
        >
        John
        >
        >
        >
        "Mark Rae [MVP]" <mark@markNOSPA Mrae.netschreef in bericht
        news:eMaEjEWoIH A.5016@TK2MSFTN GP02.phx.gbl...
        >"John Devlon" <Johndevlon@hot mail.comwrote in message
        >news:qa2Oj.176 52$_h7.2374@new sfe05.ams2...
        >>
        >>Does anyone have the correct syntax to get and set the system settings
        >>in
        >>the web.config file ?
        >>
        >http://msdn2.microsoft.com/en-us/lib...onmanager.aspx
        >>
        >>I would like to read and change the smtp server, login, password and
        >>from adress....
        >>
        >Be aware that any changes to web.config while the web app is running will
        >cause it to recycle, thereby tearing down all currently active
        >sessions...
        >>
        >>
        >--
        >Mark Rae
        >ASP.NET MVP
        >http://www.markrae.net
        >
        >

        Comment

        • Hans Kesting

          #5
          Re: get/set data web.config

          John Devlon brought next idea :
          Thanx Mark,
          >
          I didn't know that.... Better to store the data somewhere else then....
          >
          John
          >
          The values you mention seem pretty static, so a one-time configuration
          at install is all that is needed. In that case web.config is fine.
          Values that have to be changed frequently are best kept elsewhere (some
          custom config file, database)

          Hans Kesting
          >
          >
          "Mark Rae [MVP]" <mark@markNOSPA Mrae.netschreef in bericht
          news:eMaEjEWoIH A.5016@TK2MSFTN GP02.phx.gbl...
          >"John Devlon" <Johndevlon@hot mail.comwrote in message
          >news:qa2Oj.176 52$_h7.2374@new sfe05.ams2...
          >>
          >>Does anyone have the correct syntax to get and set the system settings in
          >>the web.config file ?
          >>
          >http://msdn2.microsoft.com/en-us/lib...onmanager.aspx
          >>
          >>I would like to read and change the smtp server, login, password and from
          >>adress....
          >>
          >Be aware that any changes to web.config while the web app is running will
          >cause it to recycle, thereby tearing down all currently active sessions...
          >>
          >>
          >-- Mark Rae
          >ASP.NET MVP
          >http://www.markrae.net

          Comment

          • John Devlon

            #6
            Re: get/set data web.config


            Mark,

            Do you think reading and writing to a resource file using a shared class is
            a good solution ?

            Thanx

            John

            >
            "Mark Rae [MVP]" <mark@markNOSPA Mrae.netschreef in bericht
            news:eMaEjEWoIH A.5016@TK2MSFTN GP02.phx.gbl...
            >"John Devlon" <Johndevlon@hot mail.comwrote in message
            >news:qa2Oj.176 52$_h7.2374@new sfe05.ams2...
            >>
            >>Does anyone have the correct syntax to get and set the system settings
            >>in
            >>the web.config file ?
            >>
            >http://msdn2.microsoft.com/en-us/lib...onmanager.aspx
            >>
            >>I would like to read and change the smtp server, login, password and
            >>from adress....
            >>
            >Be aware that any changes to web.config while the web app is running will
            >cause it to recycle, thereby tearing down all currently active
            >sessions...
            >>
            >>
            >--
            >Mark Rae
            >ASP.NET MVP
            >http://www.markrae.net
            >
            >

            Comment

            • sloan

              #7
              Re: get/set data web.config


              You can try this trick:


              <?xml version = "1.0" encoding = "utf-8" ?>

              <configuratio n>

              <appSettings file="CustomApp Settings.config " >

              </appSettings>

              </configuration>



              Contents of CustomAppSettin gs.config

              --start, do not include this line
              <appSettings>

              <add key="demokey1" value="demovalu e1" />

              </appSettings>

              --end, do not include this line


              And this is Peter's great writeup about it.





              I don't think the webapp is recycled with this method. I haven't
              specifically tested it.

              ...

              Don't forget to add POST BUILD events if you doing non asp.net stuff
              (winforms, console apps, etc).
              (this comment for future readers more than you, since you're doing asp.net)







              "John Devlon" <Johndevlon@hot mail.comwrote in message
              news:mv2Oj.5683 2$Lq5.25405@new sfe18.ams2...
              Thanx Mark,
              >
              I didn't know that.... Better to store the data somewhere else then....
              >
              John
              >
              >
              >
              "Mark Rae [MVP]" <mark@markNOSPA Mrae.netschreef in bericht
              news:eMaEjEWoIH A.5016@TK2MSFTN GP02.phx.gbl...
              >"John Devlon" <Johndevlon@hot mail.comwrote in message
              >news:qa2Oj.176 52$_h7.2374@new sfe05.ams2...
              >>
              >>Does anyone have the correct syntax to get and set the system settings
              >>in
              >>the web.config file ?
              >>
              >http://msdn2.microsoft.com/en-us/lib...onmanager.aspx
              >>
              >>I would like to read and change the smtp server, login, password and
              >>from adress....
              >>
              >Be aware that any changes to web.config while the web app is running will
              >cause it to recycle, thereby tearing down all currently active
              >sessions...
              >>
              >>
              >--
              >Mark Rae
              >ASP.NET MVP
              >http://www.markrae.net
              >
              >

              Comment

              • Mark Rae [MVP]

                #8
                Re: get/set data web.config

                "John Devlon" <Johndevlon@hot mail.comwrote in message
                news:hX2Oj.7665 6$5o5.5808@news fe15.ams2...
                >>Does anyone have the correct syntax to get and set the system settings
                >>in
                >>the web.config file ?
                >>
                >http://msdn2.microsoft.com/en-us/lib...onmanager.aspx
                >>
                >>I would like to read and change the smtp server, login, password and
                >>from adress....
                >>
                >Be aware that any changes to web.config while the web app is running will
                >cause it to recycle, thereby tearing down all currently active
                >sessions...
                >
                Do you think reading and writing to a resource file using a shared class
                is a good solution ?
                It largely depends what you're trying to do and why you're trying to do
                it...

                If the values that you want to read out of web.config are unlikely to change
                very often, I'd probably read them into Application variables at
                Application_Sta rt and then refer to them from there thereafter...

                However, if they are likely to change quite often, then web.config probably
                isn't the best place to start from anyway...


                --
                Mark Rae
                ASP.NET MVP


                Comment

                Working...