Recommended Middleware Order in ASP.NET Core for Secure, Fast, and Correct Pipelines

Discover the optimal middleware order for ASP.NET Core. See why each step matters, how to avoid common pitfalls, and use a proven pipeline template for secure, fast, and maintainable web APIs.

July 3, 2025 · 5 min · 942 words · Abhinaw

ASP.NET Core HTTP Logging Middleware: 10 Practical Micro Tips

TL;DR - Practical Tips for ASP.NET Core HTTP Logging Middleware Use EnableBuffering() to safely log request bodies and reset stream position after reading. Capture response bodies by swapping HttpResponse.Body with a MemoryStream and restoring after logging. Always filter or redact sensitive data before logging HTTP bodies. Set size limits and skip large or binary payloads to avoid performance issues. Filter logs by endpoint, HTTP method, or custom attributes for clarity. Built-in HttpLogging is simple; custom middleware offers full control and advanced filtering. Use structured logging and external services for production monitoring. Wrap middleware in extension methods for clean, configurable registration. 1. How does EnableBuffering help you log request bodies in ASP.NET Core? EnableBuffering allows you to read request bodies multiple times without breaking the pipeline. ...

July 2, 2025 · 8 min · 1572 words · Abhinaw

ASP.NET Core Middleware: Difference Between Use, Run, and Map Explained

Learn the key differences between Use, Run, and Map in ASP.NET Core middleware. See practical analogies, code samples, and a comparison table to master pipeline flow and build clean, maintainable APIs.

July 2, 2025 · Last modified: July 3, 2025 · 5 min · 1057 words · Abhinaw

Implementing Request Throttling Middleware in ASP.NET Core Using MemoryCache and Per-IP Limits

Protect your ASP.NET Core APIs from abuse with custom request throttling middleware using IMemoryCache and per-IP limits. Learn to implement, configure, and monitor rate limiting for robust, high-performance APIs.

July 2, 2025 · 11 min · 2326 words · Abhinaw
Diagram showing HTTP request and response flow through custom logging middleware with stream capturing and rewinding techniques

Mastering Request and Response Body Logging in ASP.NET Core Middleware

TL;DR Use custom middleware to log HTTP request and response bodies in ASP.NET Core for better debugging and diagnostics. Implement stream rewinding to read request bodies without breaking downstream middleware. Always redact sensitive data and use selective logging to avoid performance and security issues. Handle large bodies by truncating logs and excluding static or health check endpoints. Consider built-in HttpLogging for simple scenarios, but use custom middleware for full control and compliance. We’ve all been there, stuck debugging an API issue for hours, wishing we could just see what’s actually coming in and going out of our application. That’s exactly what request and response body logging solves. ...

June 25, 2025 · Last modified: June 29, 2025 · 13 min · 2750 words · Abhinaw