asp.net core获取自定义json的配置内容

首先在主目录下建立:Iyibank.Web.json文件

里边的内容如下:

{
"ConnectionStrings": {
"RedisCache": "127.0.0.1:6379"
}
}

在其他需要调用RedisCache的地方调用如下:

var builder = new ConfigurationBuilder().AddJsonFile("Iyibank.Web.json", optional: false, reloadOnChange: true);
var configuration = builder.Build();
var con= configuration.GetConnectionString("RedisCache");

原文地址:https://www.cnblogs.com/zhangkjun/p/6143396.html