[英]How to add Azure service call to appsettings.json
I'm trying to follow a tutorial on adding an Azure Cognitive Search service to my .NET Core app, and don't want to mess anything up.我正在尝试按照教程将 Azure 认知搜索服务添加到我的 .NET 核心应用程序,并且不想搞砸任何事情。 The tutorial says to add the following to my appsettings.json file:
该教程说将以下内容添加到我的 appsettings.json 文件中:
{
"SearchServiceName": "<placeholder-Azure-Search-service-name>",
"SearchServiceAdminApiKey": "<placeholder-admin-key-for-Azure-Search>",
"AzureSqlConnectionString": "<placeholder-ADO.NET-connection-string",
}
Problem is, my appsettings.json file already has stuff in it:问题是,我的 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": "*"
}
When I try to add the Azure API call at the bottom it says only one top-level item is allowed, and if I assign some key to it inside the top-level json object I'm afraid the API won't work -- I don't use JSON very much and I'm new to .NET so sorry if this is a stupid question, I couldn't find any docs explaining what to do When I try to add the Azure API call at the bottom it says only one top-level item is allowed, and if I assign some key to it inside the top-level json object I'm afraid the API won't work --我不太使用 JSON,而且我是 .NET 的新手,如果这是一个愚蠢的问题,我很抱歉,我找不到任何文档来解释该怎么做
It means your JSON is incorrect, you need to have it in the form of object with a key.这意味着您的 JSON 不正确,您需要以 object 的形式使用密钥。 Do something like
做类似的事情
{
"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"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.