79388609

Date: 2025-01-26 13:42:46
Score: 2
Natty:
Report link

I finally managed to resolve the issue. I was implementing the IMiddleware interface wrongly. Need not inject any RequestDelegate in the constructor of the custom middleware class. When implementing the InvokeAsync method, simply use RequestDelegate directly in the method signature to process incoming requests.

I have updated the code block for GlobalExceptionHandlingMiddleware in the question I posted. Also have updated the code block for Startup.cs with the correct and functional code block. No need to add services for ILogger explicitly. Everything working like a charm!

For detailed understanding pl see these two links, everything will be clear:

  1. https://www.youtube.com/watch?v=H3EbflpXVmo
  2. https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/extensibility?view=aspnetcore-9.0
Reasons:
  • Blacklisted phrase (1): youtube.com
  • Long answer (-0.5):
  • No code block (0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Prabir Choudhury