Reading the Response.Body stream in Filter

前端 未结 2 1373
不思量自难忘°
不思量自难忘° 2021-01-20 01:33

I writing my filter that running after a sever method call and print its content to Console. The code is written in ASP.NET core v2.1:

public class MyCustomF         


        
2条回答
  •  星月不相逢
    2021-01-20 02:14

    It all depends on what do you want to achieve. If you want to get the response values or just to see the result you can use

    context.Result or context.Result.Value
    

    If you want to modify the response or just to log the entire response you should use a middleware.

    here is a good example https://exceptionnotfound.net/using-middleware-to-log-requests-and-responses-in-asp-net-core/

    hope it helps

提交回复
热议问题