dotnet-middleware-patterns

Guide ASP.NET Core middleware component ordering and implementation for HTTP pipelines.

1|Updated Feb 22, 2026
One-click install
npx skills add https://github.com/rudironsoni/dotnet-agent-harness --skill dotnet-middleware-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-middleware-patterns
Source: https://github.com/rudironsoni/dotnet-agent-harness/tree/main/.rulesync/skills/dotnet-middleware-patterns
Command: npx skills add https://github.com/rudironsoni/dotnet-agent-harness --skill dotnet-middleware-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers understand and correctly implement middleware in ASP.NET Core applications, preventing common errors related to pipeline ordering, request handling, and exception management.

Core Features & Use Cases

  • Pipeline Ordering: Learn the correct sequence for essential middleware like routing, authentication, and exception handling.
  • Custom Middleware: Create reusable middleware components using both convention-based classes and the IMiddleware interface.
  • Request/Response Handling: Implement logic to short-circuit requests, manipulate request/response bodies, and handle exceptions gracefully.
  • Use Case: Ensure your ASP.NET Core application correctly handles CORS policies, authentication, and custom request logging by understanding the precise order and implementation of each middleware.

Quick Start

Use the dotnet-middleware-patterns skill to generate a basic custom middleware class for logging request timing.

Frequently Asked Questions about dotnet-middleware-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I order ASP.NET Core middleware components in the HTTP request pipeline?

ASP.NET Core middleware components must be added in a specific sequence where exception handling precedes routing and authentication, ensuring the HTTP request pipeline executes flow correctly and catches errors before pipeline short-circuiting occurs.

What is the difference between convention-based middleware classes and the IMiddleware interface in C#?

Convention-based middleware classes rely on an Invoke method and constructor injection, while the IMiddleware interface uses scoped service injection per request. Both approaches build reusable ASP.NET Core pipeline components for request and response manipulation.

How do I short-circuit the HTTP pipeline in ASP.NET Core to stop request processing?

To short-circuit the HTTP pipeline in ASP.NET Core, omit calling the next delegate within your custom middleware. This stops request processing immediately, bypassing subsequent components in the pipeline execution flow for specific conditions.

Why does my ASP.NET Core exception handling middleware fail to catch pipeline errors?

Exception handling middleware fails to catch pipeline errors when placed after routing or authentication components in the ASP.NET Core pipeline. Exception strategies must be registered early to wrap inner request handling and catch errors gracefully.

Can I manipulate the request and response bodies directly within custom ASP.NET Core middleware?

Yes, you can manipulate request and response bodies directly within custom ASP.NET Core middleware by accessing streams before invoking the next component. Inline delegates allow altering HTTP pipeline traffic for logging or data transformation.

What's the best way to implement custom request logging middleware in an ASP.NET Core application?

The best way to implement custom request logging middleware is creating a convention-based class or inline delegate that measures request timing. Register it early in the ASP.NET Core pipeline to capture execution flow accurately across all HTTP requests.