简体   繁体   English

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

[英]unable to Read the config file data from local drive

I fail to read the appSettings from a config file. 我无法从配置文件中读取appSettings。 It is not located in the default location so when I tried using var aWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"]; 它不在默认位置,因此当我尝试使用var aWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"]; it didn't work. 它没有用。

Config file: 配置文件:

<appSettings>
    <add key="AWSAccessKey" value="1" />
    <add key="AWSSecretKey" value="2" />
    <add key="AWSRegion" value="4" />
    <add key="AWSAccountNumber" value="5" />
</appSettings>

Also tried with no success: 也尝试没有成功:

var fileMap = new ConfigurationFileMap("D:AWS\\CoreLocalSettings.config");
var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);
var sectionGroup = configuration.GetSectionGroup("applicationSettings");

Finally it's working: 终于可以了:

In the app.config file I read the outside config file data as below app.config文件中,我读取了外部配置文件数据,如下所示

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

In the code base I am accessing same using the ConfigurationManager 在代码库中,我正在使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM