Response body for request/response Logging

前端 未结 3 721
花落未央
花落未央 2021-02-09 04:55

I\'m trying to write a Owin midleware component that would LOG every incoming request and response to the database.

Here\'s how far I managed to get.

I got stu

3条回答
  •  春和景丽
    2021-02-09 05:26

    Response body is a write-only network stream by default for Katana hosts. You will need to replace it with a MemoryStream, read the stream, log the content and then copy the memory stream content back into the original network stream. BTW, if your middleware reads the request body, downstream components cannot, unless the request body is buffered. So, you might need to consider buffering the request body as well. If you want to look at some code, http://lbadri.wordpress.com/2013/08/03/owin-authentication-middleware-for-hawk-in-thinktecture-identitymodel-45/ could be a starting point. Look at the class HawkAuthenticationHandler.

提交回复
热议问题