Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Web.config path

Web.config path

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminhelpquestion
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    seee sharp
    wrote on last edited by
    #1

    Hello, In ASP.NET 2.0 how can I find the path of web.config file inside code at runtime. For instance there is AppDomain.CurrentDomain.SetupInformation.ConfigurationFile But in my case I cannot use this. Because, my assembly is in at different place and web config file is at different place (wwwroot) When I use above method, I get location of assembly, not the root folder i.e. wwwroot Appreciate any help. Note: I need to get this path where Server.MapPath is not available.

    - ashish

    G 1 Reply Last reply
    0
    • S seee sharp

      Hello, In ASP.NET 2.0 how can I find the path of web.config file inside code at runtime. For instance there is AppDomain.CurrentDomain.SetupInformation.ConfigurationFile But in my case I cannot use this. Because, my assembly is in at different place and web config file is at different place (wwwroot) When I use above method, I get location of assembly, not the root folder i.e. wwwroot Appreciate any help. Note: I need to get this path where Server.MapPath is not available.

      - ashish

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      You can only get the path when MapPath is available. If it's really not available, you have to store the value when it is, so that you can get it when it isn't. If the code is run because of a request, you can always use MapPath. You can reach it through HttpContext.Current.Server.MapPath. MapPath("~") gets the root folder. The root may or may not contain a web.config file. Each subfolder may also contain a web.config file.

      --- b { font-weight: normal; }

      S 1 Reply Last reply
      0
      • G Guffa

        You can only get the path when MapPath is available. If it's really not available, you have to store the value when it is, so that you can get it when it isn't. If the code is run because of a request, you can always use MapPath. You can reach it through HttpContext.Current.Server.MapPath. MapPath("~") gets the root folder. The root may or may not contain a web.config file. Each subfolder may also contain a web.config file.

        --- b { font-weight: normal; }

        S Offline
        S Offline
        seee sharp
        wrote on last edited by
        #3

        Hello Guffa, I have my virtual dir configured at drive X and my wwwroot folder is in drive C. The webconfig file I have to keep in wwwroot folder. I am using Enterprise Lib for caching. The ConfigurationBuilder of this uses AppDomain.CurrentDomain.SetupInformation.ConfigurationFile to get config file path. In my case above statement does not return the value I am looking for that is, wwwroot folder path. Inside Enterprise Lib’s ConfigurationBuilder class I do not have HttpContext available. Hope you understand where I am. Let me know if you have any clue, any workaround to get it running. Appreciate your help.

        - ashish

        S G 2 Replies Last reply
        0
        • S seee sharp

          Hello Guffa, I have my virtual dir configured at drive X and my wwwroot folder is in drive C. The webconfig file I have to keep in wwwroot folder. I am using Enterprise Lib for caching. The ConfigurationBuilder of this uses AppDomain.CurrentDomain.SetupInformation.ConfigurationFile to get config file path. In my case above statement does not return the value I am looking for that is, wwwroot folder path. Inside Enterprise Lib’s ConfigurationBuilder class I do not have HttpContext available. Hope you understand where I am. Let me know if you have any clue, any workaround to get it running. Appreciate your help.

          - ashish

          S Offline
          S Offline
          seee sharp
          wrote on last edited by
          #4

          In addition to previous I can access right config keys by using System.Configuration.ConfigurationManager.AppSettings In web config only I have defined the path for appsettings.xml file and it reads properly.

          - ashish

          1 Reply Last reply
          0
          • S seee sharp

            Hello Guffa, I have my virtual dir configured at drive X and my wwwroot folder is in drive C. The webconfig file I have to keep in wwwroot folder. I am using Enterprise Lib for caching. The ConfigurationBuilder of this uses AppDomain.CurrentDomain.SetupInformation.ConfigurationFile to get config file path. In my case above statement does not return the value I am looking for that is, wwwroot folder path. Inside Enterprise Lib’s ConfigurationBuilder class I do not have HttpContext available. Hope you understand where I am. Let me know if you have any clue, any workaround to get it running. Appreciate your help.

            - ashish

            G Offline
            G Offline
            Guffa
            wrote on last edited by
            #5

            AshishBasran wrote:

            Inside Enterprise Lib’s ConfigurationBuilder class I do not have HttpContext available.

            Why not? When is the code executed?

            --- b { font-weight: normal; }

            S 1 Reply Last reply
            0
            • G Guffa

              AshishBasran wrote:

              Inside Enterprise Lib’s ConfigurationBuilder class I do not have HttpContext available.

              Why not? When is the code executed?

              --- b { font-weight: normal; }

              S Offline
              S Offline
              seee sharp
              wrote on last edited by
              #6

              It get executed when on load of first page I try to use caching and for that from entprise lib request goes to ConfigurationBuilder for configuration section

              - ashish

              G 1 Reply Last reply
              0
              • S seee sharp

                It get executed when on load of first page I try to use caching and for that from entprise lib request goes to ConfigurationBuilder for configuration section

                - ashish

                G Offline
                G Offline
                Guffa
                wrote on last edited by
                #7

                Then the code is executed as a result of a request, and you can access the current HttpContext.

                --- b { font-weight: normal; }

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups