无法从本地驱动器读取配置文件数据
本文关键字:读取 配置文件 数据 驱动器 | 更新日期: 2023-09-27 17:54:20
从配置文件中读取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"];