Middleware & Request Pipeline Flashcards
6 cards from real ASP.NET Core practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 6 Middleware & Request Pipeline flashcards as text
What is the purpose of app.Run() in the middleware pipeline?
Answer: Adds a terminal middleware that never calls next()
app.Run() adds a terminal middleware delegate that handles requests without forwarding to any subsequent middleware.
Which middleware enables exception handling and custom error pages in production?
Answer: UseExceptionHandler
UseExceptionHandler() catches unhandled exceptions and redirects to a custom error path in production.
What does app.Map() do in the middleware pipeline?
Answer: Branches the pipeline based on request path
app.Map() creates a branch in the pipeline that executes when the request path starts with a specified prefix.
In which interface must a custom middleware class implement its logic?
Answer: IMiddleware with InvokeAsync method
A class-based middleware implements IMiddleware and defines its logic in the InvokeAsync(HttpContext, RequestDelegate) method.
What is the correct order for security middleware in ASP.NET Core?
Answer: CORS → Authentication → Authorization
The correct order is UseRouting → UseCors → UseAuthentication → UseAuthorization to ensure security works correctly.
Which middleware is responsible for populating HttpContext.User from cookies or tokens?
Answer: UseAuthentication
UseAuthentication() processes authentication tokens/cookies and populates HttpContext.User with the authenticated identity.