Azure 应用程序设置中的 ConnectionStrings 在

问题描述 投票:0回答:1

我正在尝试检索存储在应用程序设置、Azure 中的 Web 应用程序的连接字符串中的连接字符串。该应用程序在本地运行正常,但是当我发布到 Azure 时,对 AddAzureAppConfiguration 的调用会抛出错误,提示连接字符串为空。

using IssueIdentityAPI;


var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

string issueIdentityAPIConfigConnectionString = builder.Configuration.GetConnectionString("AppConfig");
// Load configuration from Azure App Configuration
builder.Configuration.AddAzureAppConfiguration(issueIdentityAPIConfigConnectionString);

Azure 门户中的连接字符串名称为“ConnectionStrings:AppConfig”。我之前将其命名为“AppConfig”,但这会产生相同的行为。怎么解决?

asp.net azure connection-string azure-application-settings
1个回答
0
投票

在 Azure 门户中,您可以在 2 个位置添加连接字符串:应用程序设置和连接字符串。您可以在这些部分之一中添加连接字符串: Screenshot showing where to add connection strings in Azure portal configurations

  1. 如果您在“应用程序设置”部分中添加连接字符串,则格式应为以下 TopObjectNameInJson__NestedPropertyName。在您的情况下,它将是 ConnectionStrings__AppConfig。 Azure 使用双下划线 (__) 来指示 appsettings.json 文件中的嵌套属性。 Screenshot showing how you can add your connection strings in the Application Settings section
  2. 如果您在“连接字符串”部分添加连接字符串,则只需使用连接字符串属性名称即可覆盖。在你的例子中,它只是 AppConfig。 Screenshot showing how you can add your connection strings in the Connection Strings section
© www.soinside.com 2019 - 2024. All rights reserved.