c# - 如何从计时器触发器获取 azure 函数运行位置的主机名?

标签 c# azure-functions

我有一个定时器触发器

    [FunctionName("HeathChecker")]
    public static void Run([TimerTrigger("*/10 * * * * *")]TimerInfo myTimer, ILogger log)
    {
        log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");


    }

还有一个 HTTP 触发器

    [FunctionName("AspNetCoreHost")]
    public Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Anonymous, Route = "{*all}")]HttpRequest req,
        [AspNetCoreRunner(Startup = typeof(Startup))] IAspNetCoreRunner aspNetCoreRunner,
        ExecutionContext executionContext)
    {

        return aspNetCoreRunner.RunAsync(executionContext);
    }

我希望能够获取运行 HTTP 触发器的主机名,这样我就可以从定时器触发器中使用 HTTP 调用它。这可能吗?

最佳答案

您还可以从 HttpRequest req 对象中获取主机名:

HostString hostString = req.Host;
string host = hostString.Host;
int? port = hostString.Port;
string fullHost = hostString.Value; 

关于c# - 如何从计时器触发器获取 azure 函数运行位置的主机名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56586433/

相关文章:

azure - 我收到 Azure REST API 403 禁止错误

C# - FtpWebRequest 的多种方法?

c# - WPF MVVM 在您键入时更改文本框大小

c# - 是否可以使用 XML 查询命令转储 MySQL 数据库?

c# - 如何避免使用 C# 在 MongoDB 中重复插入而不使用 "_id"键?

c# - 如何使用Azure Functions将数据发送到服务总线主题?

azure - 使用带有属性的预编译 C# 时,是否可以在 Azure 函数中拥有多个输出绑定(bind)?

C#程序问题

azure - 在哪里可以找到用 Powershell 编写的 Http 触发器函数的应用服务日志?

Azure 函数失败和警告