[英]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.