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.