Web.config path
-
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
-
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
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; }
-
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; }
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
-
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
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
-
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
-
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; }
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
-
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