Custom HttpMessageHandler to save http request and response in DB
Hi, is it good idea to overide SendAsync method from DelegateHandler and save request and response in DB?
https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpmessagehandler?view=net-8.0
I made custom HttpMessageHandler and inject repository in it, but when I call SaveChanges I got concurrency exception over db context when I run multiple http requests in parallel, everything is registered in DI correctly. So my question where is best place to save http request and http response in db?
HttpMessageHandler Class (System.Net.Http)
A base type for HTTP message handlers.
11 Replies
Are you sure you would want to store requests and responses in a database, and not just log them to a logging system?
But besides that, you'd have to show some code on what you've already tried. This doesn't sound like a problem with httpmessagehandler, rather with how you work with your DB
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Basically c/p of this:
https://stackoverflow.com/questions/73803758/different-threads-using-same-instance-of-dbcontext-called-from-within-delegatin
Stack Overflow
Different threads using same instance of DbContext, called from wit...
I have .Net Core 3.1 application that is using EF Core 3.1.9. During a specific process I am getting the following error:
A second operation started on this context before a previous operation com...
I'm aware of this but this is just for testing purpose, will not use on production.
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Why so angry 🤣
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
You are right, so your advice would be to use asp.net core middleware UseHttpLogging()?
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
UseHttpLogging also logs responses
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View