Azure函数应用程序IfunctionInvocationFilter在请求执行后失去了请求主体

发布于 2025-01-23 06:17:54 字数 956 浏览 2 评论 0原文

我在Azure函数上有一个过滤器,该函数在完成主函数操作完成后立即执行某些任务。

    public async Task<IActionResult> DoStuff(
                [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "notImportant")]
                HttpRequest req,
                ClaimsPrincipal principal)
            {
              string bodyContent = await new StreamReader(req.Body).ReadToEndAsync();  //Always has content
            }

我的过滤器看起来像这样:

public class TraceAuditFilter : IFunctionInvocationFilter
    {
       

        public TraceAuditFilter()
        {
            
        }


        public async Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
        {
          var request = (HttpRequest)executedContext.Arguments["req"];
          string body = new StreamReader(req.Body).ReadToEnd(); //Always Empty
        }
}

我的过滤器可成功地触发,但是过滤器方法中的“正文”总是空的。有什么想法正在重置它?

I have a filter on an Azure Function that performs some tasks right after the the main function action has completed.

    public async Task<IActionResult> DoStuff(
                [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "notImportant")]
                HttpRequest req,
                ClaimsPrincipal principal)
            {
              string bodyContent = await new StreamReader(req.Body).ReadToEndAsync();  //Always has content
            }

My Filter looks like this:

public class TraceAuditFilter : IFunctionInvocationFilter
    {
       

        public TraceAuditFilter()
        {
            
        }


        public async Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
        {
          var request = (HttpRequest)executedContext.Arguments["req"];
          string body = new StreamReader(req.Body).ReadToEnd(); //Always Empty
        }
}

My filter sucessfully fires, but the 'body' in the filter method is always Empty. Any ideas what is resetting it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感受沵的脚步 2025-01-30 06:17:54

我们需要将功能过滤类添加为属性。

这可能是一个原因,因为该函数中没有调用过滤器。

您需要将[TraceAuditFilter]添加到该功能中,以便可以传递过滤器。

请参阅以下文章以获取深入的解释: -
ifunctionInvocationFilter

href =“ https://donotpanic.azurewebsites.net/2019/10/14/improve-azure-function-logging-with-function-with-function-filters/” rel =“ nofollow noreferrer”>函数过滤器

We need to add the function filter class as an attribute.

That might be a reason as the filter is not being invoked in the functions.

You need to add [TraceAuditFilter] to the function so that the filter can be passed.

Refer the following articles for Indepth explanation: -
IFunctionInvocationFilter

function filters

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文