无法从本地驱动器读取配置文件数据

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");
    var AWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];
    var web = System.Web.Configuration.WebConfigurationManager
      .OpenWebConfiguration(@"D:\Employee\Hitesh\Projects\Web.config");

    var appValue = web.AppSettings.Settings["SMTPServerPort"].Value;

终于成功了:

app.config 文件中,我读取了如下外部配置文件数据

<configuration>
    <appSettings file="D:\AWS\CoreLocalSettings.config">
    .......
    </appSettings>
</configuration>

在代码库中,我使用 ConfigurationManager

进行访问
var strAWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];