简体   繁体   English

.net 5,secrets.json,appsettings.json 和 Z3A580F142203677F1F0BC3089 应用程序设置

[英].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 存储在appsettingssecrets.json教程。

You could check things below:您可以检查以下内容:

  1. If you configure UserSecretsId in your project file?如果在项目文件中配置UserSecretsId
  2. Register the user secrets configuration source. 注册用户机密配置源。
  3. Read the secret via the Configuration API in correct format. 通过配置 API 以正确的格式读取密钥。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GCP Google Cloud Platform - Cloud Run - .NET 5.0 - 来自机密的应用程序设置或转换 appsettings.json - GCP Google Cloud Platform - Cloud Run - .NET 5.0 - Application settings from secrets or transform appsettings.json 将 appsettings.json 文件中的机密存储在 Azure Key Vault 上的 .Net 控制台应用程序中 - Store secrets from appsettings.json file in .Net Console Application on Azure Key Vault Azure webjobs不会使用Azure应用程序设置覆盖appsettings.json - Azure webjobs does not override appsettings.json with Azure Application Settings 使用.NET Core中的appsettings.json设置继承 - Inheritance with appsettings.json settings in .NET Core .NET 6 应用程序未读取链接的 appsettings.json - .NET 6 application is not reading linked appsettings.json 在 .NET 核心控制台应用程序中将 appsettings.json 设置放入 class 类型的 object 中 - Getting appsettings.json settings into an object of class type in .NET Core console application 如何在 .NET Core 的 appSettings.json 上配置 IdentiyServer 设置? - How to configure IdentiyServer settings on appSettings.json of .NET Core? ASP.NET Core appsettings.json 未加载正确的设置 - ASP.NET Core appsettings.json not loading the correct settings 如何在控制台应用程序 (.net Core) 中将数据写入 appsettings.json? - How to write data to appsettings.json in a console application (.net Core)? 如何在 a.Net 6 控制台应用程序中读取 appsettings.json? - How can I read the appsettings.json in a .Net 6 console application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM