我想从appsettings.json获取整个部分。
这是我的appsettings.json:
{
"AppSettings": {
"LogsPath": "~/Logs",
"SecondPath": "~/SecondLogs"
}
}
C#:
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile(this.SettingsFilesName);
configuration = builder.Build();
此语法可以正常工作,并返回“〜/ Logs”:
configuration.GetSection("AppSettings:LogsPath");
但是我如何拥有所有的“ AppSettings”部分?有可能吗?
此语法无效,并且value属性为null。
configuration.GetSection("AppSettings");
UPDATE:
我没有模型,只能在课堂上阅读。我正在寻找这样的东西:
var all= configuration.GetSection("AppSettings");
并像]一样使用它>
all["LogsPath"] or all["SecondPath"]
他们将它们的价值还给我。
我想从appsettings.json获取整个部分。这是我的appsettings.json:{“ AppSettings”:{“ LogsPath”:“〜/ Logs”,“ SecondPath”:“〜/ SecondLogs”}} C#:var builder = new ...