C# 从另一个目录中的Web.config文件读取值
我在同一个目录中部署了两个web服务。我试图从一个Web服务的C# 从另一个目录中的Web.config文件读取值,c#,web-services,C#,Web Services,我在同一个目录中部署了两个web服务。我试图从一个Web服务的Web.config文件中读取另一个Web服务的值。这可能吗 我试过这个,但不起作用: protected static string GetApplicationSettings(string sKey) { string sValue = null; System.Configuration.Configuration rootWebConfig =
Web.config
文件中读取另一个Web服务的值。这可能吗
我试过这个,但不起作用:
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;
}
试试这个:
ConfigurationFileMap fileMap = new ConfigurationFileMap(file); //Path to your config file
Configuration configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
string value = configuration.AppSettings.Settings["sKey"].Value;
找到它可能你找错地方了。尝试给出完整的路径。。