【发布时间】:2020-06-24 01:45:51
【问题描述】:
我已将我的 API 配置为使用托管标识从 Azure KeyVault 获取 Azure 存储连接字符串。
现在的问题是,当我在 Visual Studio 中本地运行代码时,它不再使用来自 appsettings.development.json 的连接字符串 "StorageAccount": "UseDevelopmentStorage=true"
因此我在本地运行时无法使用模拟器。
我在控制器中创建了以下条件来解决此问题:
public FileController(IConfiguration configuration, IWebHostEnvironment env)
{
this.configuration = configuration;
if (env.IsDevelopment())
{
conn = this.configuration.GetConnectionString("StorageAccount");
}
else
{
conn = this.configuration["StorageConnectionString"];
}
}
这是正确的做法吗?
【问题讨论】:
标签: azure azure-storage azure-keyvault