Middleware and the ASP.NET Core Request Pipeline
Middleware and the ASP.NET Core Request Pipeline
Section titled βMiddleware and the ASP.NET Core Request PipelineβASP.NET Core handles each request by passing it through an ordered middleware pipeline. Each middleware component can inspect the request, perform work, call the next component, and shape the response.
Common Pipeline Responsibilities
Section titled βCommon Pipeline Responsibilitiesβ- exception handling
- HTTPS redirection
- authentication and authorization
- CORS
- logging and diagnostics
- endpoint execution
Why Order Matters
Section titled βWhy Order MattersβMiddleware order changes behavior. For example, authentication and authorization must run before protected endpoints execute.
Practical Rule
Section titled βPractical RuleβKeep middleware for cross-cutting concerns. Keep business logic in application services and endpoints.