![](/img/trans.png)
[英]Entity framework Azure SQL connection string in appsettings.json
[英]How to add Azure service call to appsettings.json
我正在嘗試按照教程將 Azure 認知搜索服務添加到我的 .NET 核心應用程序,並且不想搞砸任何事情。 該教程說將以下內容添加到我的 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": "*"
}
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 的新手,如果這是一個愚蠢的問題,我很抱歉,我找不到任何文檔來解釋該怎么做
這意味着您的 JSON 不正確,您需要以 object 的形式使用密鑰。 做類似的事情
{
"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.