Last post Sep 25, 2019 09:55 AM by Yongqing Yu
Sep 10, 2019 02:33 PM|shubhrajit|LINK
Hi Currently we have Web.config, Web.QA.config , Web.Prod.config under asp.net application project and also we do have Web.config in subfolder. Depend upon the properties it reads data from subfolder specific Web.config. But now due to some requirement instead
of Web.config we are setting up Web.QA.config and Web.prod.config to APP_CONFIG_FILE depend upon the environment and put this logic to Application_Start method in Global.asax . So now every time instead of Web.config we get the data from environment specific
config file. But problem is we are not able to read data from subfolder specific Web.config. I added both Web.QA.config , Web.Prod.config in same subfolder but still not working. So please help me to get data from subfolder specific config file.
Sep 11, 2019 09:25 AM|Yongqing Yu|LINK
So please help me to get data from subfolder specific config file.
If you want to get data from subfloder specific config file, you can use
these codes to achieve it :
ConfigurationFileMap fileMap = new ConfigurationFileMap("~/Root/Sub1/Web.config"); //Path to your config file
Configuration configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
string value = configuration.AppSettings.Settings["sKey"].Value;
Sep 11, 2019 09:53 AM|PatriceSc|LINK
Not crystal clear. Which info do you want to read from a child web.config file? The configuration is hierarchical so I would expect to be able to read values from this child web.config for an http request that matches this virtual path or below.
See perhaps https://weblogs.asp.net/jongalloway/10-things-asp-net-developers-should-know-about-web-config-inheritance-and-overrides
Sep 11, 2019 05:59 PM|shubhrajit|LINK
Sep 12, 2019 09:27 AM|Yongqing Yu|LINK
According to your description, if you want to get configsection from your subfolder web.config, you should ensure your configsection's type is an available and accessible dll.
Then you can use this code to get it :
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
configMap.ExeConfigFilename = Server.MapPath("~/test/Web.config");//get the path of your subfolder web.config
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
string section = ConfigurationManager.GetSection("OrderTotalsValuesSection").ToString();
catch (Exception ex)
I recommend you use try-catch to ensure your configsection's type is right.
Sep 12, 2019 10:49 AM|mgebhard|LINK
This web.config configuration Web.config, Web.QA.config , Web.Prod.config is related web.config transforms in ASP.NET. Simply change the solution configuration
to deploy the deploy the correct transform.
In ASP.NET Core it's the environment configuration.
The subfolder design does not make sense or at least it is not clear how the change in requirements change how ASP,NET Configuration works fundamentally.
Sep 12, 2019 12:17 PM|PatriceSc|LINK
which suppose to retrieve from subfolder
AFAIK no. A web.config files applies to the folder where it is placed and child folders... So if you try to read the config file while processing a request that matches the root virtual path rather than this subfolder, not seeing the information coming from
the web.config file placed in this folder is the behavior I expect.
Is this your real intent ? If you want something to be available everywhere in your app it should be placed in the web.config file placed at the root of your web app.
Maybe not directly related but how config files are handled is a bit unusual. As suggested already you want to look instead at https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations
Sep 24, 2019 10:57 AM|shubhrajit|LINK
Sep 25, 2019 09:55 AM|Yongqing Yu|LINK
According to your description, I'm still not sure what you need.
Do you want to get the contents of web.debug.config or web.release.config file under web.config?
I hope you can describe your needs in more detail, which will help us solve your issues more easily.