web.config in a class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?SmVycnkgQw==?=

    web.config in a class


    I need to access the web.config file in a class. I am now using the line:

    rootWebConfig1 = WebConfiguratio nManager.OpenWe bConfiguration( "~")

    to get a reference to the config file. The question is the correct way to
    get the config file in classes. There is only one config file and it is in
    the root of the web site. I do not want to use a path since the location of
    the web site can change. The classes will be in the App_Code dir.



    Thank you,

    --
    Jerry
  • Steve

    #2
    Re: web.config in a class

    Your cide looks correct to me. You are using the tilde to indicate the root
    directory, which is always relative to the site, so should work wherever you
    put the code. What problem are you having with this?

    Also, are you planning to read or write the web.config? Note that changes in
    the web.config file will cause the Web server to restart, and will also
    refresh the cache entries, which may cause problems in your application

    HTH

    "Jerry C" <jerryed@nospam .nospamwrote in message
    news:1D5334F9-773B-4829-BA02-0B40FC4DE6C4@mi crosoft.com...
    >
    I need to access the web.config file in a class. I am now using the line:
    >
    rootWebConfig1 = WebConfiguratio nManager.OpenWe bConfiguration( "~")
    >
    to get a reference to the config file. The question is the correct way to
    get the config file in classes. There is only one config file and it is in
    the root of the web site. I do not want to use a path since the location
    of
    the web site can change. The classes will be in the App_Code dir.
    >
    >
    >
    Thank you,
    >
    --
    Jerry

    Comment

    • =?Utf-8?B?SmVycnkgQw==?=

      #3
      Re: web.config in a class

      Steve,

      Thank you for you reply,
      I am not having any problems with the code. I was checking the community to
      see if I was using the correct code. This app started with framework 1 and I
      run into old code. Just checking for the latest.

      Thank you
      --
      Jerry


      "Steve" wrote:
      Your cide looks correct to me. You are using the tilde to indicate the root
      directory, which is always relative to the site, so should work wherever you
      put the code. What problem are you having with this?
      >
      Also, are you planning to read or write the web.config? Note that changes in
      the web.config file will cause the Web server to restart, and will also
      refresh the cache entries, which may cause problems in your application
      >
      HTH
      >
      "Jerry C" <jerryed@nospam .nospamwrote in message
      news:1D5334F9-773B-4829-BA02-0B40FC4DE6C4@mi crosoft.com...

      I need to access the web.config file in a class. I am now using the line:

      rootWebConfig1 = WebConfiguratio nManager.OpenWe bConfiguration( "~")

      to get a reference to the config file. The question is the correct way to
      get the config file in classes. There is only one config file and it is in
      the root of the web site. I do not want to use a path since the location
      of
      the web site can change. The classes will be in the App_Code dir.



      Thank you,

      --
      Jerry
      >
      >
      >

      Comment

      • Allen Chen [MSFT]

        #4
        Re: web.config in a class

        Hi Jerry,

        Yes your code is correct.

        Regards,
        Allen Chen
        Microsoft Online Support
        --------------------
        | Thread-Topic: web.config in a class
        | thread-index: Ackn+DHlonxjN67 AShKQCxnenpaCCQ ==
        | From: =?Utf-8?B?SmVycnkgQw= =?= <jerryed@nospam .nospam>
        | References: <1D5334F9-773B-4829-BA02-0B40FC4DE6C4@mi crosoft.com>
        <u42roG9JJHA.46 72@TK2MSFTNGP05 .phx.gbl>
        | Subject: Re: web.config in a class
        | Date: Mon, 6 Oct 2008 14:12:09 -0700
        | Lines: 46
        | Message-ID: <0A84BD2E-E8AD-49C7-95FD-6F1232976E3C@mi crosoft.com>
        | MIME-Version: 1.0
        | Content-Type: text/plain;
        | charset="Utf-8"
        | Content-Transfer-Encoding: 7bit
        | X-Newsreader: Microsoft CDO for Windows 2000
        | Content-Class: urn:content-classes:message
        | Importance: normal
        | Priority: normal
        | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.3119
        | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
        | Path: TK2MSFTNGHUB02. phx.gbl
        | Xref: TK2MSFTNGHUB02. phx.gbl
        microsoft.publi c.dotnet.framew ork.aspnet:7740 2
        | NNTP-Posting-Host: tk2msftibfm01.p hx.gbl 10.40.244.149
        | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
        |
        | Steve,
        |
        | Thank you for you reply,
        | I am not having any problems with the code. I was checking the community
        to
        | see if I was using the correct code. This app started with framework 1
        and I
        | run into old code. Just checking for the latest.
        |
        | Thank you
        | --
        | Jerry
        |
        |
        | "Steve" wrote:
        |
        | Your cide looks correct to me. You are using the tilde to indicate the
        root
        | directory, which is always relative to the site, so should work
        wherever you
        | put the code. What problem are you having with this?
        | >
        | Also, are you planning to read or write the web.config? Note that
        changes in
        | the web.config file will cause the Web server to restart, and will also
        | refresh the cache entries, which may cause problems in your application
        | >
        | HTH
        | >
        | "Jerry C" <jerryed@nospam .nospamwrote in message
        | news:1D5334F9-773B-4829-BA02-0B40FC4DE6C4@mi crosoft.com...
        |
        | I need to access the web.config file in a class. I am now using the
        line:
        |
        | rootWebConfig1 = WebConfiguratio nManager.OpenWe bConfiguration( "~")
        |
        | to get a reference to the config file. The question is the correct
        way to
        | get the config file in classes. There is only one config file and it
        is in
        | the root of the web site. I do not want to use a path since the
        location
        | of
        | the web site can change. The classes will be in the App_Code dir.
        |
        |
        |
        | Thank you,
        |
        | --
        | Jerry
        | >
        | >
        | >
        |

        Comment

        • Steve

          #5
          Re: web.config in a class

          Excellent. Working code is always easier to troubleshoot ;-)

          "Jerry C" <jerryed@nospam .nospamwrote in message
          news:0A84BD2E-E8AD-49C7-95FD-6F1232976E3C@mi crosoft.com...
          Steve,
          >
          Thank you for you reply,
          I am not having any problems with the code. I was checking the community
          to
          see if I was using the correct code. This app started with framework 1 and
          I
          run into old code. Just checking for the latest.
          >
          Thank you
          --
          Jerry
          >
          >
          "Steve" wrote:
          >
          > Your cide looks correct to me. You are using the tilde to indicate the
          >root
          >directory, which is always relative to the site, so should work wherever
          >you
          >put the code. What problem are you having with this?
          >>
          >Also, are you planning to read or write the web.config? Note that changes
          >in
          >the web.config file will cause the Web server to restart, and will also
          >refresh the cache entries, which may cause problems in your application
          >>
          >HTH
          >>
          >"Jerry C" <jerryed@nospam .nospamwrote in message
          >news:1D5334F 9-773B-4829-BA02-0B40FC4DE6C4@mi crosoft.com...
          >
          I need to access the web.config file in a class. I am now using the
          line:
          >
          rootWebConfig1 = WebConfiguratio nManager.OpenWe bConfiguration( "~")
          >
          to get a reference to the config file. The question is the correct way
          to
          get the config file in classes. There is only one config file and it is
          in
          the root of the web site. I do not want to use a path since the
          location
          of
          the web site can change. The classes will be in the App_Code dir.
          >
          >
          >
          Thank you,
          >
          --
          Jerry
          >>
          >>
          >>

          Comment

          • =?Utf-8?B?TWFydGluIEJpc2Nob2Zm?=

            #6
            RE: web.config in a class

            In my class library projects I'm using the following code to access the
            configuration file:

            string myValue =
            System.Configur ation.Configura tionManager.App Settings.Get("m yEntry");

            This code exists since the .NET 1.x times and still works. It has (IMO) one
            advantage over your solution, which is that it also works when the class
            library is used by a windows forms application.

            --
            Martin

            "Jerry C" wrote:
            >
            I need to access the web.config file in a class. I am now using the line:
            >
            rootWebConfig1 = WebConfiguratio nManager.OpenWe bConfiguration( "~")
            >
            to get a reference to the config file. The question is the correct way to
            get the config file in classes. There is only one config file and it is in
            the root of the web site. I do not want to use a path since the location of
            the web site can change. The classes will be in the App_Code dir.
            >
            >
            >
            Thank you,
            >
            --
            Jerry

            Comment

            Working...