c# - Azure Web 应用程序未从配置选项卡中获取值

标签 c# asp.net-core azure-web-app-service

我开发了一个 asp.net 核心 API,可将图像保存到 Azure blob 存储帐户并在 cosmos DB 中插入 blob URI。

在我的本地,它按预期工作。 (我正在从本地的 appsetting.json 读取存储帐户和 cosmos Db 连接字符串)。

我在 Azure Web 应用程序中部署了我的服务,这次我想从 Azure Web 应用程序配置(设置 --> 配置选项卡)中读取这些连接,而不是从 appsettings.json 中读取。所以我在 azureweb 应用程序本身中提供了配置,如屏幕截图中所述。

enter image description here

但是当我调用我的端点时它显示以下错误(说我的连接字符串为空)

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/

相关文章:

c# - C#打开最小化窗体的方法

c# - 在 XAML 中绑定(bind)到自身/'this'

c# - 在 Asp Net Core 6 中使用 Github 进行身份验证

c# - 从 WebAPI 发送大文件。内容长度为 0

c# - Azure web.app AI : Performance counter is not available in the web app supported list

c# - customUserNamePasswordValidatorType 是怎么回事?

c# - protobuf-net 是否支持可空类型?

c# - 哪个组件正在处理 ASP.NET Core 中的线程分配?

azure-devops - 使用保管库 secret 的 Azure DevOps 文件转换

azure - 通过 postman 验证来自 Azure 应用服务的 token 返回 401