[英].net 5, secrets.json, appsettings.json and Azure Application Settings
I have a .net (core) 5 application which I am trying to setup so that sensitive values are held in secrets.json file, and when the application is published to Azure I can then use the Application settings area of the app service to provide the values from here instead.我有一个 .net(核心)5 应用程序,我正在尝试设置它,以便敏感值保存在 secrets.json 文件中,当应用程序发布到 Z3A580F142203677F1F0BC 时,可以使用应用程序设置区域的应用程序设置区域 I30898F63F3取而代之的是这里的值。
However, I am unable to use both at the same time.但是,我无法同时使用两者。
In my secrets.json file I have:在我的 secrets.json 文件中,我有:
{
"UserName": "LocalUserName"
}
In my appsettings.json file I have:在我的 appsettings.json 文件中,我有:
{
"UserName": ""
}
As I understand that I need the same structure, but without the value assigned to the key.据我了解,我需要相同的结构,但没有分配给键的值。
In my Startup.cs file I can reference: Username = Configuration["Username"]
Which only gets the blank key in the appsettings.json file instead of the secrets.json file在我的 Startup.cs 文件中,我可以参考:
Username = Configuration["Username"]
仅获取 appsettings.json 文件中的空白密钥,而不是 secrets.json 文件
In the Application settings area I am setting:在我正在设置的应用程序设置区域中:
{
"name": "Username",
"value": "PublishedUserName",
"slotSetting": false
}
But is not picked up.但是没有捡到。
I have seen references to use ConfigurationManager.AppSettings["Username"];
我已经看到使用
ConfigurationManager.AppSettings["Username"];
的引用。 instead.反而。 But if I use this, then this doesn't reference either of my json files when debugging.
但是如果我使用它,那么在调试时它不会引用我的 json 文件。
I'm new to using .net core, so I'm struggling.我是使用 .net 内核的新手,所以我很挣扎。 In essence what I'm trying to do is replicate what I would have with an appsettingssecrets.config file outside of the application in a .net framework solution.
本质上,我想要做的是在 .net 框架解决方案中复制应用程序外部的 appsettingssecrets.config 文件。 Which I can then reference the same keys in Azure and provide published values from there.
然后我可以引用 Azure 中的相同键并从那里提供发布的值。
Here is a tutorial about how to store appsettings
in secrets.json
.这是有关如何将 appsettings 存储在
appsettings
中secrets.json
教程。
You could check things below:您可以检查以下内容:
UserSecretsId
in your project file?UserSecretsId
?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.