以编程方式从事件网格触发函数中获取函数 app url

Programmatically get function app url from event grid triggered function

在一个 HTTP 触发的 azure 函数中我们可以得到 url 如下

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)
{
    
}

objective 是从事件网格触发函数调用同一函数应用程序上的 HTTP 触发函数。

获取httptrigger的url的简单示例:

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

(Azure默认会提供一个安全域。所以我们可以使用'https'。)