繁体   English   中英

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

[英]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.

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