Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

I am using the following line of code to dynamically load the web.config file at runtime. But it only loads the root web.config.

Can any one solve this problem?
VB
Dim a As String = Request.Url.Host.ToString()
        If Request.Url.Host.Contains("tes1.com") Then

            Try
                Me.MasterPageFile = "~/TestLogo1.master"

                ' Set the root path of the Web application that contains the
                ' Web.config file that you want to access.
                ' Get the configuration object to access the related Web.config file.


                Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration("~/Web2.config")
                ' Get the object related to the <appsettings> section.
                Dim section As AppSettingsSection = DirectCast(config.GetSection("appSettings"), AppSettingsSection)

                ' Read the <appsettings> section.
                'StringBuilder appSettings = new StringBuilder();
                'appSettings.Append("WebConfig1");
                'appSettings.Append(section.Settings["WebConfig1"].ToString());
                Dim SettingValue As String = section.Settings("WebConfig2").Value

                ' Display the <appsettings> information.
                'ConfigId.Text = appSettings.ToString();
                Response.Write(SettingValue)
            Catch ex As Exception
                Response.Write(ex)
            End Try</appsettings></appsettings></appsettings>

Thanks in Advance
Posted
Updated 1-Jun-10 1:17am
v2

Web.config should be only one for each virtual directory. Even if you place multiple web.config in one folder, ConfigurationManager will only parse the file Web.config. Others you need to read it manually.

Have a look at these links to have multiple config file:
Include Multiple .Config Files in ASP.NET Web Application[^]
Using multiple config files in one application[^]
 
Share this answer
 
thanks sandeep for your answer i have already visited the links but it did not solve my problem
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900