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



从配置文件中读取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:AWSCoreLocalSettings.config">
    .......
    </appSettings>
</configuration>

在代码库中我使用ConfigurationManager

访问相同的
var strAWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];
    var web = System.Web.Configuration.WebConfigurationManager
      .OpenWebConfiguration(@"D:EmployeeHiteshProjectsWeb.config");
    var appValue = web.AppSettings.Settings["SMTPServerPort"].Value;
    var AWSAccessKey = ConfigurationManager.AppSettings["AWSAccessKey"];

相关内容

  • 没有找到相关文章

最新更新