Azure 应用程序配置 - 如何设置 secret

标签 azure azure-configuration azure-app-configuration

我关注this guide设置 Azure 应用程序配置。

但我想我误解了这句话:

dotnet user-secrets set ConnectionStrings:AppConfig "Endpoint=<your_endpoint>;Id=<your_id>;Secret=<your_secret>"

或者更确切地说;什么是什么...

  • your_endpoint = 我设置了主键连接字符串(从 Azure 中的应用配置资源复制)
  • your_id = guid 设置为 UserSecretsId(指南中的几个步骤)
  • your_secret = key 的 key (指南中的 ConnectionStrings:AppConfig)

但是我的程序总是在以下位置崩溃:

config.AddAzureAppConfiguration(settings["ConnectionStrings:AppConfig"]);

异常(exception):

System.FormatException HResult=0x80131537 Message=The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. Source=System.Private.CoreLib StackTrace: at System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength) at System.Convert.FromBase64String(String s) at Microsoft.Azure.AppConfiguration.Azconfig.AzconfigClient..ctor(String connectionString, HttpMessageHandler httpMessageHandler, Boolean disposeHandler) at Microsoft.Extensions.Configuration.AzureAppConfiguration.AzureAppConfigurationSource.Build(IConfigurationBuilder builder) at Microsoft.Extensions.Configuration.ConfigurationBuilder.Build() at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(AggregateException& hostingStartupErrors) at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() at Persistance.API.Program.Main(String[] args) in C:\Repos\experiment\experiment\Program.cs:line 19

执行此代码块时(来自指南):

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration((hostingContext, config) =>
    {
        var settings = config.Build();
        config.AddAzureAppConfiguration(settings["ConnectionStrings:AppConfig"]);
    })
    .UseStartup<Startup>();

右键单击项目 -> 管理用户 secret 我有这个 json 文件:

 {
    "Movies:ServiceApiKey": "12345",
    "ConnectionStrings:AppConfig": "Endpoint=<Primary Key Connection String copied value from azure resource>;Id=<the UserSecretsId tag in csproj file>;Secret=<the Key value in App Configuration resource>"
 }

值得注意;我的主键连接字符串包含字符“;”、“-”、“+”和“=”,但这些不应该是非法字符...

最佳答案

这里的关键不是解释连接字符串的各个部分,而是将其视为不透明的标记。连接字符串可以直接从门户复制或通过azure CLI获取

az extension add -n appconfig
az appconfig credential list -n <your-app-configuration-name>

获得连接字符串后,应使用准确、完整的值来调用 AddAzureAppConfiguration。连接字符串的“ secret ”部分很可能以“=”字符结尾,我怀疑它没有被复制。

关于Azure 应用程序配置 - 如何设置 secret ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55244060/

相关文章:

azure - @Query 在 Spring Boot (JPA) + Azure Cosmos db 中不起作用

asp.net-core - ASP.NET Core(最新)- appsettings.json ConnectionString 未在 Azure 上覆盖

azure - 如何在运行时从 Web 服务内部获取 CloudConfiguration 的完整列表?

node.js - 访问引用 Node.js 中的 Key Vault 的 Azure 应用程序配置设置

azure - 如何获取 azure devops 项目项目管理员组的成员

适用于 PowerShell 7 的 Azure 自动化混合工作人员 Get-AutomationPSCredential

azure - 以原子方式将设置推送到 azure 应用程序配置

asp.net - 我可以使用Environment.GetEnvironmentVariable方法从Azure应用程序设置中读取环境变量吗?

azure - 如何从多个 Azure 订阅中导出虚拟机名称和 IP 地址

azure - 从管理门户中完全删除订阅