简体   繁体   English

API 连接字符串在部署到 Azure 后不起作用

[英]API Connection String Not Working After Deploying to Azure

First, I am well aware this may be a duplicate.首先,我很清楚这可能是重复的。 I have looked but have not yet found a solution.我看过但还没有找到解决办法。 If you can point me to one, I will gladly accept it!如果你能指点我一个,我很乐意接受!

I've built an API in VS 2019 using Core 5.0.我使用 Core 5.0 在 VS 2019 中构建了 API。 This is the entire appsettings.json file:这是整个 appsettings.json 文件:

{
  "AppSettings": {
    "ConnectionStrings": {
      "DefaultConnection": "Server=...."
    }
  },
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
}

Works perfectly in localhost.在本地主机中完美运行。 But when I publish to Azure, all the results come back:但是当我发布到 Azure 时,所有结果都回来了:

The ConnectionString property has not been initialized ConnectionString 属性尚未初始化

SOME articles I have read say that the App Service will use the appsettings.json file that comes with the app.我读过的一些文章说应用服务将使用应用程序附带的appsettings.json文件。 Others say you need to add them manually in Azure Portal.还有人说需要在Azure Portal中手动添加。 I have tried adding the connection string manually, in multiple ways:我尝试以多种方式手动添加连接字符串:

在此处输入图像描述

But I still get the same result.但我仍然得到相同的结果。

What am I doing wrong?我究竟做错了什么?

You need to take the ConnectionStrings out of AppSettings to a higher level as below, also make sure you are mentioning the same in the portal您需要将 ConnectionStrings 从 AppSettings 中取出到更高级别,如下所示,还要确保您在门户中提及相同

"ConnectionStrings": {
    "Default": "server=v6.com;database=tsde;uid=sa;pwd=234@123."
  },

I found something which may be useful on https://docs.microsoft.com : Configure apps我发现了一些可能对https://docs.microsoft.com有用的东西: 配置应用程序

For ASP.NET and ASP.NET Core developers, setting app settings in App Service are like setting them in in Web.config or appsettings.json, but the values in App Service override the ones in Web.config or appsettings.json. For ASP.NET and ASP.NET Core developers, setting app settings in App Service are like setting them in in Web.config or appsettings.json, but the values in App Service override the ones in Web.config or appsettings.json. You can keep development settings (for example, local MySQL password) in Web.config or appsettings.json and production secrets (for example, Azure MySQL database password) safely in App Service. You can keep development settings (for example, local MySQL password) in Web.config or appsettings.json and production secrets (for example, Azure MySQL database password) safely in App Service. The same code uses your development settings when you debug locally, and it uses your production secrets when deployed to Azure相同的代码在本地调试时使用您的开发设置,在部署到 Azure 时使用您的生产机密

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET Core API 在 Azure 上部署后无法正常工作 - .NET Core API not working after deploying on Azure 部署到 Azure 后 DocumentClient 不起作用 - DocumentClient not working after deploying to Azure 将 Web API 部署到 Azure - Entity Framework Core 迁移连接字符串未被拾取 - Deploying Web API to Azure - Entity Framework Core migrations connection string not being picked up 更改存储帐户连接字符串后 Azure Function App 无法正常工作 - Azure Function App not working after changing storage account connection string 部署到Azure Web应用程序后Bootstrap下拉菜单不起作用 - Bootstrap dropdown not working after deploying to azure webapps 部署连接字符串 - Deploying connection string 仅在部署到IIS之后,Azure API上出现403错误 - 403 Error on Azure API Only After Deploying to IIS 部署到Azure后OAuth无法正常工作[ASP.NET MVC] - OAuth not working after deploying to Azure [ASP.NET MVC] Azure发布数据库第一个连接字符串不起作用 - Azure Publish Database First Connection String Not Working Azure IoT中心连接字符串不再起作用-Azure是否更新连接字符串? - Azure IoT hub connection string not working anymore - Does azure update the connection string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM