相关疑难解决方法(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万
查看次数

Azure应用程序设置不会覆盖我的appsettings.json文件值

我尝试将我的appsettings.json文件中的DefaultConnection添加到Azure的应用程序设置中,但Azure不会覆盖连接字符串.

在此输入图像描述

在此输入图像描述

我能找到的任何文章或博客都指出我需要做的就是在appsettings.json文件中添加连接字符串名称,Azure应该完成剩下的工作(例如https://tehremo.wordpress.com/2016/ 10/07/override-connection-strings-app-settings-in-asp-net-core-and-azure-app-service /)然而,当应用程序发布时,它使用我的本地连接字符串.

我的Startup.cs文件如下所示:

在此输入图像描述 在此输入图像描述

注意:我使用VSTS持续交付发布"部署Azure应用服务"发布任务.

appsettings azure asp.net-core

21
推荐指数
2
解决办法
1万
查看次数

标签 统计

asp.net-core ×2

.net ×1

.net-core ×1

appsettings ×1

azure ×1

c# ×1