ICONFIGURATION不会从AppSettings.json检索值,而是从Azure密钥库中检索值

发布于 2025-01-27 14:14:27 字数 603 浏览 2 评论 0原文

在.NET Core 3.1 Web API的程序中,我得到了以下内容:

    public class Program
{

    private static string _someValue;

    public Program(IConfiguration configuration)
    {
        _someValue = configuration["SOME_VALUE"]

    }

appsettings.json Ins Inside:我得到的:

{
 "Logging": {
    "LogLevel": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
    }
},
 "SOME_VALUE": "value"

}

问题是,我无法从AppSettings.json中获取值“ some_value”。但是我在Azure密钥库中获得了相同的值,由于某种原因,它从那里获得了值。有人可以解释为什么是这种情况吗?

Inside the Program.cs file of a .NET Core 3.1 Web API i got the following:

    public class Program
{

    private static string _someValue;

    public Program(IConfiguration configuration)
    {
        _someValue = configuration["SOME_VALUE"]

    }

inside the appsettings.json i got:

{
 "Logging": {
    "LogLevel": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
    }
},
 "SOME_VALUE": "value"

}

The problem is, i am not able to get the value "SOME_VALUE" from the appsettings.json. But i got this same value inside an Azure Key Vault and for some reason it gets the values from there. Can someone explain why that is the case?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫嚣ゝ 2025-02-03 14:14:27

配置提供商以特定顺序执行

在您的情况下,Azure KeyVault将位于顶部(或者更确切地说,它在AdderSecrets和AddenVironMentVariables之间)

请参见docs

代码中的订单配置提供商适合基础配置源的优先级该应用需要或使用其他变量名称

Configuration providers are executed in a specific order
enter image description here

In your case, the Azure KeyVault will be at the top (or, to be more precise it is between AddUserSecrets and AddEnvironmentVariables)

See docs

Order configuration providers in code to suit the priorities for the underlying configuration sources that the app requires or use different variable name

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文