1

I have two web services deployed in the same directory. I am trying to read a value from Web.config file of one of the web services from the other. Is this possible?

i tried this but its not working:

  protected static string GetApplicationSettings(string sKey)
        {
            string sValue = null;
            System.Configuration.Configuration rootWebConfig =
               System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/WebServiceTest/WebServiceTest/web.config");
            //check if the AppSettings section has items
            if (rootWebConfig.AppSettings.Settings.Count > 0)
            {
                sValue = rootWebConfig.AppSettings.Settings[sKey].Value;
            }
            return sValue;
        }
Oluwafemi
  • 14,243
  • 11
  • 43
  • 59
Rashad.Z
  • 2,494
  • 2
  • 27
  • 58

1 Answers1

2

Try this:

ConfigurationFileMap fileMap = new ConfigurationFileMap(file); //Path to your config file
Configuration configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
string value = configuration.AppSettings.Settings["sKey"].Value;

Found it here

Community
  • 1
  • 1