【问题标题】:How to add Azure service call to appsettings.json如何将 Azure 服务调用添加到 appsettings.json
【发布时间】:2020-08-10 13:46:30
【问题描述】:

我正在尝试按照教程将 Azure 认知搜索服务添加到我的 .NET Core 应用程序,并且不想搞砸任何事情。该教程说将以下内容添加到我的 appsettings.json 文件中:

{
  "SearchServiceName": "<placeholder-Azure-Search-service-name>",
  "SearchServiceAdminApiKey": "<placeholder-admin-key-for-Azure-Search>",
  "AzureSqlConnectionString": "<placeholder-ADO.NET-connection-string",
}

问题是,我的 appsettings.json 文件里已经有东西了:

{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=xxx.database.windows.net,1433;Initial Catalog=XChange;Persist Security Info=False;User ID=xxx;Password=xxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

当我尝试在底部添加 Azure API 调用时,它说只允许一个顶级项目,如果我在顶级 json 对象中为其分配一些键,恐怕 API 不会工作——我不太使用 JSON,而且我是 .NET 的新手,如果这是一个愚蠢的问题,我很抱歉,我找不到任何解释该做什么的文档

【问题讨论】:

    标签: asp.net json asp.net-mvc azure


    【解决方案1】:

    这意味着你的 JSON 不正确,你需要以对象的形式拥有它,并带有一个键。做类似的事情

     {
      "ConnectionStrings": {
        "DefaultConnection": "Data Source=xxx.database.windows.net,1433;Initial Catalog=XChange;Persist Security Info=False;User ID=xxx;Password=xxx;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
      },
      "Logging": {
        "LogLevel": {
          "Default": "Information",
          "Microsoft": "Warning",
          "Microsoft.Hosting.Lifetime": "Information"
        }
      },
      "AllowedHosts": "*",
      "Configuration": {
        "SearchServiceName": "<placeholder-Azure-Search-service-name>",
        "SearchServiceAdminApiKey": "<placeholder-admin-key-for-Azure-Search>",
        "AzureSqlConnectionString": "<placeholder-ADO.NET-connection-string"
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      • 2015-12-04
      • 2015-08-15
      • 1970-01-01
      • 2020-09-15
      相关资源
      最近更新 更多