【问题标题】:Azure Function .NET5 Isolated Process Get Path Param from HttpRequestDataAzure Function .NET5 隔离进程从 HttpRequestData 获取路径参数
【发布时间】:2021-12-01 15:13:26
【问题描述】:

我有路径“/todo/{id}”,我想获取 Id 路径参数。

        [Function("Run")]
        public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get",
            Route = "todo/{id}")] HttpRequestData req,
            FunctionContext executionContext)
        {
            var logger = executionContext.GetLogger("GetTodo");
            logger.LogInformation("C# HTTP trigger function processed a request.");

            var response = req.CreateResponse(HttpStatusCode.OK);
            response.Headers.Add("Content-Type", "text/plain; charset=utf-8");

            response.WriteString("Welcome to Azure Functions!");

            return response;
        }

我如何才能访问 Id?

提前致谢!

【问题讨论】:

    标签: azure-functions .net-5 azure-http-trigger


    【解决方案1】:

    可以包含绑定输入。

    你可以通过在方法参数中放置变量来获取路径参数。

            [Function("Run")]
            public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get",
                Route = "todo/{id}")] HttpRequestData req, string id,
                FunctionContext executionContext) 
    {
                var logger = executionContext.GetLogger("GetTodo");
                logger.LogInformation("C# HTTP trigger function processed a request.");
    
                logger.LogInformation("This is the id - {id}", id);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-14
      • 2022-01-22
      • 2022-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多