Azure WebJobs:是否可以在控制台应用程序中以编程方式检索主机 Url?

Azure WebJobs: Is it possible to retrieve the Host Url programmatically in the console app?

我想从我的 WebJob 调用 REST 调用,我想知道是否可以通过编程方式从我的 WebJob 中检索主机 Url (http://<something>.azurewebsites.net),而不是硬-编码 URL.

在您的队列监控方法中,您可以传递对 CloudStorageAccount 的引用并获取队列端点,例如:

    public async Task ProcessQueueMessageAsync([QueueTrigger("queue")] string message, CloudStorageAccount account)
    {
        var endpoint = account.QueueEndpoint;
    }

Web 应用程序主机名可以从 WEBSITE_HOSTNAME 环境变量中读取。

可以找到环境描述,包括环境变量 here。可以使用位于 https://<web_app>.scm.azurewebsites.net.

的 Kudu 仪表板查看环境变量及其值