I follow this guide to set up Azure App Configuration.
But I think I misunderstand this line:
dotnet user-secrets set ConnectionStrings:AppConfig "Endpoint=<your_endpoint>;Id=<your_id>;Secret=<your_secret>"
Or rather; what is what...
But then my program always crash at:
config.AddAzureAppConfiguration(settings["ConnectionStrings:AppConfig"]);
with 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
when executing this code block (from guide):
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
var settings = config.Build();
config.AddAzureAppConfiguration(settings["ConnectionStrings:AppConfig"]);
})
.UseStartup<Startup>();
Right-click on project -> Manage User Secrets I have this json file:
{
"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>"
}
Worth noting; my primary key connection string contains chars ';', '-', '+' and '=' but those shouldn't be illeagal characters...
答案 0 :(得分:1)
此处的关键不是解释连接字符串的各段,而是将其当作不透明的标记。连接字符串可以直接从门户网站复制,也可以通过azure CLI获取
az extension add -n appconfig
az appconfig credential list -n <your-app-configuration-name>
一旦有了连接字符串,就应使用准确,完整的值来调用AddAzureAppConfiguration
。连接字符串的“秘密”部分很可能以“ =”字符结尾,我怀疑它没有被复制。
答案 1 :(得分:0)
我想到两件事:
如果在.net核心中使用此功能,则可以在配置内部的launch.json中指定以下内容:
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},