我是 Azure's function 的新手...我创建了一个新的计时器函数(每 30 分钟触发一次),它必须对 URL 执行查询,然后将数据推送到缓冲区。
我已经完成了
public static void Run(TimerInfo myTimer, TraceWriter log)
{
var s = CloudConfigurationManager.GetSetting("url");
log.Info(s);
}
在我的功能设置中,我已经
我做错了什么? 谢谢
最佳答案
请注意,对于 Azure Functions v2,情况不再如此。 以下来自Jon Gallant's blog :
对于 Azure Functions v2,不支持 ConfigurationManager,您必须使用 ASP.NET Core 配置系统:
包含以下using 语句:
using Microsoft.Extensions.Configuration;
包含 ExecutionContext 作为参数
public static void Run(InboundMessage inboundMessage, TraceWriter log, out string outboundMessage, ExecutionContext context)
获取
IConfiguration
根var config = new ConfigurationBuilder() .SetBasePath(context.FunctionAppDirectory) .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true) .AddEnvironmentVariables() .Build();
并用它来引用 AppSettings 键
var password = config["password"]
在本地调试时,它会从“Values”关键字下的 local.settings.json
获取设置。在 Azure 中运行时,它从“应用程序设置”选项卡获取设置。
关于c# - 从 Azure Function 读取设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43556311/