相关疑难解决方法(0)

如何从ASP.NET Core中的.json文件中读取AppSettings值

我在appsettings/Config .json中设置了我的AppSettings数据,如下所示:

{
  "AppSettings": {
        "token": "1234"
    }
}
Run Code Online (Sandbox Code Playgroud)

我在网上搜索了如何从.json文件中读取AppSettings值,但我无法获得任何有用的信息.

我试过了:

var configuration = new Configuration();
var appSettings = configuration.Get("AppSettings"); // null
var token = configuration.Get("token"); // null
Run Code Online (Sandbox Code Playgroud)

我知道在ASP.NET 4.0中你可以这样做:

System.Configuration.ConfigurationManager.AppSettings["token"];
Run Code Online (Sandbox Code Playgroud)

但是我如何在ASP.NET Core中执行此操作?

.net c# .net-core asp.net-core

199
推荐指数
21
解决办法
24万
查看次数

标签 统计

.net ×1

.net-core ×1

asp.net-core ×1

c# ×1