C
C#•5mo ago
TJacken

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
Sossenbinder
Sossenbinder•5mo ago
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
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
TJacken
TJackenOP•5mo ago
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...
TJacken
TJackenOP•5mo ago
I'm aware of this but this is just for testing purpose, will not use on production.
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
TJacken
TJackenOP•5mo ago
Why so angry 🤣
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
TJacken
TJackenOP•5mo ago
You are right, so your advice would be to use asp.net core middleware UseHttpLogging()?
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Joschi
Joschi•5mo ago
UseHttpLogging also logs responses
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server