【发布时间】:2018-08-29 15:35:38
【问题描述】:
我正在尝试在我的 Asp.net Core 项目中读取 .json 文件。
打印
dbConfig.json
{
"AzureCosmosDb": {
"EndpointUrl": "https://localhost:8081",
"PrimaryKey": "C2y6yDjf5/R++4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==",
"DatabaseId": "Cosmoso"
},
"Oracle12c": {
}
}
在dbConfig.Json中搜索文件中的值的代码:
public static string GetConnectionString(string fileJson, string conexao)
{
var builder = new ConfigurationBuilder().AddJsonFile(fileJson);
Configuration = builder.Build();
string connection = Configuration.GetConnectionString("AzureCosmosDb:DatabaseId");
return connection;
}
方法返回null,怎么回事?
【问题讨论】:
标签: c# asp.net-core