appsettings.json 在部署为 Azure Function App 容器时可以正确读取,但在部署为简单的 Azure Function App 时则无法正确读取
我有一个功能应用程序,该应用程序成功地在本地运行,成功运行为“ Azure函数应用程序容器”, 但是,当我试图将其简单地部署为“ Azure函数应用程序”时,发布后,它无法读取我在AppSettings.json文件中放置的字段(我将其放在S3密钥访问和秘密键以及其他方面) ,所显示的错误是“未配置了没有regionEndpoint或serviceurl”,应从appsettings.json文件中获取。 这就是我的创业课程中发生的事情:
public override void Configure(IFunctionsHostBuilder builder)
{
var config = new ConfigurationBuilder()
.SetBasePath(Environment.CurrentDirectory)
.AddJsonFile("appsettings.json", false)
.AddUserSecrets(Assembly.GetExecutingAssembly(), false)
.AddEnvironmentVariables()
.Build();
builder.Services.AddLogging();
builder.Services.AddSingleton<IConfiguration>(config);
builder.Services.AddSingleton(svc =>
{
var client = new AzureLogAnalyticsClient(
config[LogAnalyticsWorkspaceID],
config[LogAnalyticsKey]);
client.TimeStampField = config["LogAnalyticsTimestampField"];
return client;
});
}
I have a Function App which is successfully running locally and successfully running as "Azure Function App Container",
but when I'm trying to deploy it as simply "Azure Function App", right after publishing it can't read the fields that I put in the appsettings.json file (I put there s3 key access and secret key among other things), the error that is shown is that "No RegionEndpoint or ServiceURL configured", which should be taken from the appsettings.json file.
This is what happens in my startup class:
public override void Configure(IFunctionsHostBuilder builder)
{
var config = new ConfigurationBuilder()
.SetBasePath(Environment.CurrentDirectory)
.AddJsonFile("appsettings.json", false)
.AddUserSecrets(Assembly.GetExecutingAssembly(), false)
.AddEnvironmentVariables()
.Build();
builder.Services.AddLogging();
builder.Services.AddSingleton<IConfiguration>(config);
builder.Services.AddSingleton(svc =>
{
var client = new AzureLogAnalyticsClient(
config[LogAnalyticsWorkspaceID],
config[LogAnalyticsKey]);
client.TimeStampField = config["LogAnalyticsTimestampField"];
return client;
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Azure函数应用程序部署将不会默认情况下读取AppSettings.json。相反,将这些配置值放在Azure函数的应用程序设置中。
这可以通过登录Azure Portal,转到您的Azure函数来完成:然后:
An Azure Function App deployment will not read appsettings.json by default. Instead, put those configuration values in the Azure Function's application settings.
This can be done by logging into the Azure portal, going to your Azure Function, then: