Azure函数应用程序IfunctionInvocationFilter在请求执行后失去了请求主体
我在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们需要将功能过滤类添加为属性。
这可能是一个原因,因为该函数中没有调用过滤器。
您需要将
[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