我创建了一个运行docker
图像的 AzureWebApp 。应用程序启动,但似乎没有获取连接字符串。我已将连接字符串定义为AppSetting,但我没有看到该设置作为环境变量传递。
我是否希望在容器输出上看到我的AppSetting?像
这样的东西docker run -e CONNSTR=FOO
文档暗示它应该自动传递,但我觉得我错过了什么。
由于
乔
答案 0 :(得分:2)
原来它一直在努力。我在对数据库进行身份验证时遇到了合法问题。我需要在服务中记录一些日志,以验证它是否获得了正确的连接字符串。
应用程序设置似乎是隐式传递给容器的,而不会在日志中显示为-e param。
答案 1 :(得分:1)
在部署.NET Core 2 Azure功能时遇到了类似的问题,该功能使用System.Configuration.ConfigurationManager读取设置和连接字符串。我的根本原因是ASP.NET Core引入了一个新的配置API。 在https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.0&tabs=basicconfiguration了解更多详情。
假设您正在部署部署到Web Apps for Containers的ASP.NET Core应用程序,您可能会遇到类似的问题。请尝试以下方法:
a)按如下方式初始化配置:
using Microsoft.Extensions.Configuration;
...
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("local.settings.json")
.AddEnvironmentVariables()
.Build();
b)按如下方式读取连接字符串:
configuration.GetConnectionString("StorageAccountConnectionString");
c)按如下方式读取设置:
configuration["ContainerName"];
以下是我的Azure功能的示例配置文件:
{
"IsEncrypted": true,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"AzureWebJobsDashboard": "UseDevelopmentStorage=true",
"ContainerName": "container"
},
"Host": {
"LocalHttpPort": 7071
},
"ConnectionStrings": {
"StorageAccountConnectionString": "UseDevelopmentStorage=true"
}
}