通过事件网格触发的函数以编程方式获取函数应用url

问题描述

在HTTP触发的Azure函数中,我们可以按以下方式获取网址

public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function,"get","post",Route = null)] HttpRequest req,Microsoft.Azure.WebJobs.ExecutionContext executionContext,ILogger log)
{
    string url = req.Scheme + "://" + req.Host + $"/api/AnotherFunctionOnTheApp";
}

但是我们如何在没有HTTPRequest对象的事件网格触发函数中做到这一点?

public static void Run([EventGridTrigger]EventGridEvent eventGridEvent,ILogger log)
{
    
}

目标是从事件网格触发函数在同一functionapp上调用HTTP触发函数。

解决方法

获取httptrigger网址的简单示例:

string url = "https://" + Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME") + "/api/AnotherFunctionOnTheApp";

(Azure默认情况下会提供一个安全域。因此我们可以使用“ https”。)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...