我只想从一个配置文件中读取一个连接字符串,并为此添加一个名为“ appsetings.json”的文件到我的项目中,并在其中添加以下内容:
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-
WebApplica71d622;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
在 ASP.NET 上,我用了这个:
var temp=ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
现在我如何在 C # 中读取“ DefaultConnection”并将其存储在.NET Core 中的字符串变量中呢?