我开发了一个 asp.net 核心 API,可将图像保存到 Azure blob 存储帐户并在 cosmos DB 中插入 blob URI。
在我的本地,它按预期工作。 (我正在从本地的 appsetting.json 读取存储帐户和 cosmos Db 连接字符串)。
我在 Azure Web 应用程序中部署了我的服务,这次我想从 Azure Web 应用程序配置(设置 --> 配置选项卡)中读取这些连接,而不是从 appsettings.json 中读取。所以我在 azureweb 应用程序本身中提供了配置,如屏幕截图中所述。
但是当我调用我的端点时它显示以下错误(说我的连接字符串为空)
System.ArgumentNullException: Value cannot be null. (Parameter 'connectionString')
at Azure.Storage.StorageConnectionString.Parse(String connectionString)
at Azure.Storage.Blobs.BlobServiceClient..ctor(String connectionString, BlobClientOptions options)
at Azure.Storage.Blobs.BlobServiceClient..ctor(String connectionString)
at BikesIsland.API.Startup.<>c__DisplayClass4_0.<ConfigureServices>b__0(IServiceProvider factory) in D:\a\BikesIsland\BikesIsland\BikesIsland.API\Startup.cs:line 64
这是我的 appsetting.json 结构
{
"AllowedHosts": "*",
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
}
},
"ApplicationInsights": {
"InstrumentationKey": ""
},
"CosmosDbSettings": {
"ConnectionString": "",
"DatabaseName": "bikes-island",
"BikeContainerName": "Bikes",
"EnquiryContainerName": "Enquiry",
"BikeReservationContainerName": "bike-reservation",
"BikePartitionKeyPath": "/id",
"EnquiryPartitionKeyPath": "/id",
"BikeReservationPartitionKeyPath": "/bikeId"
},
"BlobStorageSettings": {
"ConnectionString": "",
"ContainerName": "bikesimages"
},
"ServiceBusSettings": {
"ConnectionString": "",
"QueueName": "reservation"
}
}
请帮助我解决上述错误。因为我对 Azure Web 应用程序完全陌生。
提前致谢
最佳答案
这是因为您正在读取 BlobStorageSettings:ConnectionString
的值 here在你的代码中:
var value = Configuration.GetSection("BlobStorageSettings:ConnectionString").Value;
当您在应用程序设置中添加 BlobStorageSettings__ConnectionString
时。请将其更改为 BlobStorageSettings:ConnectionString
它将起作用。
关于c# - Azure Web 应用程序未从配置选项卡中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66708046/