[英]unable to Read the config file data from local drive
我无法从配置文件中读取appSettings。 它不在默认位置,因此当我尝试使用var aWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];
它没有用。
配置文件:
<appSettings>
<add key="AWSAccessKey" value="1" />
<add key="AWSSecretKey" value="2" />
<add key="AWSRegion" value="4" />
<add key="AWSAccountNumber" value="5" />
</appSettings>
也尝试没有成功:
var fileMap = new ConfigurationFileMap("D:AWS\\CoreLocalSettings.config");
var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
var sectionGroup = configuration.GetSectionGroup("applicationSettings");
终于可以了:
在app.config
文件中,我读取了外部配置文件数据,如下所示
<configuration>
<appSettings file="D:\AWS\CoreLocalSettings.config">
.......
</appSettings>
</configuration>
在代码库中,我正在使用ConfigurationManager
访问
var strAWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];
var web = System.Web.Configuration.WebConfigurationManager
.OpenWebConfiguration(@"D:\Employee\Hitesh\Projects\Web.config");
var appValue = web.AppSettings.Settings["SMTPServerPort"].Value;
var AWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.