【问题标题】:Integrate http trigger powershell azure Function app with app gateway将 http trigger powershell azure Function 应用程序与应用程序网关集成
【发布时间】:2021-09-01 12:08:23
【问题描述】:

我有一个 http 触发 azure 函数。我创建了一个应用程序网关并将其路由到函数应用程序,它似乎工作正常。但是如何路由到 http 触发函数应用呢?

【问题讨论】:

标签: azure-functions gateway


【解决方案1】:

我们可以通过修改 function1.cs 中的路由参数来更新或覆盖我们的 Http Triggered Azure 函数的路由。默认情况下,路由参数被分配为空。

假设我们希望路由以 localhost:7071/api/hello 向我们的 Azure 函数发送请求,那么我们只需将路由参数分配为 hello。

public static class Function1  
    {  
        [FunctionName("Function1")]  
        public static async Task<IActionResult> Run(  
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "Hello")] HttpRequest req,  
            ILogger log)  
        {  
            log.LogInformation("C# HTTP trigger function processed a request.");  
  
            string name = req.Query["name"];  
  
            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();  
            dynamic data = JsonConvert.DeserializeObject(requestBody);  
            name = name ?? data?.name;  
  
            string responseMessage = string.IsNullOrEmpty(name)  
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."  
                : $"Hello, {name}. This HTTP triggered function executed successfully.";  
  
            return new OkObjectResult(responseMessage);  
        }  
    }  

查看Http Trigger Function 了解有关路由的完整信息。

【讨论】:

    猜你喜欢
    • 2021-10-13
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多