C# core Net6.0 读取appsetting.json 节点数据
2024-02-23 01:45:05 1327 0
core net 6.0读取appsetting.json节点数据:
appsetting.json 文件内容:
{ "ConnectionStrings": {
//数据库连接字符串
"Connstr": "Server=127.0.0.1;Database=Test;Trusted_Connection=True;MultipleActiveResultSets=true;User Id=sa;PassWord=123"
},
"Logging":
{
"LogLevel":
{
"Default": "Information", "Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
取节点数据方法:
由于core dotnet6.0 取消了Startup.cs文件,所以我们需要在Program.cs 文件添加以下代码即可:
app.Configuration.GetConnectionString("Connstr");