ASP.NET Core Interview

Middleware & Request Pipeline

ASP.NET Core interview questions covering middleware & request pipeline.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
76
Mid-LevelIntermediate

What is middleware in ASP.NET Core?

Middleware is software assembled into the ASP.NET Core HTTP request pipeline. Each middleware component can inspect or modify the incoming request, perform work before or after the next component, and inspect or modify the outgoing response.

77
Mid-LevelIntermediate

How does the ASP.NET Core request pipeline work?

When an HTTP request reaches an ASP.NET Core application, it passes through an ordered sequence of middleware components. Each component decides whether to call the next component in the pipeline.

78
Mid-LevelIntermediate

Why is middleware order important in ASP.NET Core?

Middleware order determines which components see a request and when they run. Incorrect ordering can cause authentication, authorization, routing, static files, CORS, or exception handling to behave incorrectly.

79
Mid-LevelIntermediate

What is the difference between Use, Run, and Map in ASP.NET Core?

Use adds middleware that can call the next component in the pipeline. It is appropriate when processing should continue after the middleware performs its work.

80
Mid-LevelIntermediate

What does it mean to short-circuit the middleware pipeline?

Short-circuiting means a middleware produces a response without invoking the next middleware component.

81
Mid-LevelIntermediate

How do you create custom middleware in ASP.NET Core?

Custom middleware is commonly implemented as a class with a constructor that receives RequestDelegate and an Invoke or InvokeAsync method that accepts HttpContext.

82
Mid-LevelIntermediate

What is RequestDelegate?

RequestDelegate represents a function that processes an HttpContext asynchronously. It is the fundamental delegate used to connect middleware components in the ASP.NET Core request pipeline.

83
Mid-LevelIntermediate

What is HttpContext in ASP.NET Core?

HttpContext represents the current HTTP request and response. It provides access to Request, Response, User, Connection, Session when configured, Items, RequestServices, and other request-specific information.

84
Mid-LevelIntermediate

What are HttpRequest and HttpResponse?

HttpRequest contains information sent by the client, including the HTTP method, path, query string, headers, cookies, body, scheme, and host.

85
Mid-LevelIntermediate

What is UseRouting() in ASP.NET Core?

UseRouting adds endpoint routing middleware that matches the incoming request to an endpoint based on the application's route definitions and metadata.

86
Mid-LevelIntermediate

What is endpoint routing?

Endpoint routing is the ASP.NET Core routing system that matches requests to executable endpoints. An endpoint can represent a controller action, Razor Page, minimal API handler, SignalR hub, health check, or other endpoint type.

87
Mid-LevelIntermediate

What is UseStaticFiles()?

UseStaticFiles enables the static file middleware, which serves files such as CSS, JavaScript, images, and fonts directly to clients.

88
Mid-LevelIntermediate

What is UseHttpsRedirection()?

UseHttpsRedirection redirects incoming HTTP requests to HTTPS. It helps ensure clients use an encrypted connection when HTTPS is available.

89
Mid-LevelIntermediate

What is HSTS and UseHsts()?

HTTP Strict Transport Security (HSTS) tells compatible browsers that a site should be accessed only over HTTPS for a specified period.

90
Mid-LevelIntermediate

What is exception handling middleware in ASP.NET Core?

Exception handling middleware catches unhandled exceptions thrown by downstream components and converts them into an appropriate response.

91
Mid-LevelIntermediate

What is Developer Exception Page middleware?

The Developer Exception Page displays detailed information about unhandled exceptions, including stack traces and request-related diagnostic information.

92
Mid-LevelIntermediate

How can you implement global exception handling in modern ASP.NET Core?

Modern ASP.NET Core supports centralized exception handling through exception handling middleware and, in newer .NET versions, IExceptionHandler implementations.

93
Mid-LevelIntermediate

What is status code pages middleware?

Status code pages middleware can generate simple responses for HTTP error status codes that otherwise have no response body, such as 404 or 403 responses.

94
Mid-LevelIntermediate

What is response compression middleware?

Response compression reduces the size of eligible HTTP responses before they are sent to clients. This can reduce bandwidth usage and improve transfer time for compressible content such as JSON, HTML, CSS, and JavaScript.

95
Mid-LevelIntermediate

What is response caching middleware?

Response caching middleware implements HTTP caching behavior based on standard cache-related request and response headers.

96
Mid-LevelIntermediate

What is CORS middleware in ASP.NET Core?

Cross-Origin Resource Sharing (CORS) controls whether browser-based code from one origin is allowed to call resources hosted on another origin.

97
Mid-LevelIntermediate

Where should authentication and authorization middleware be placed?

Authentication should normally run before authorization. Authentication establishes the current user identity, while authorization evaluates whether that user is allowed to access the selected resource.

98
Mid-LevelIntermediate

How can middleware access dependency-injected services?

A conventional middleware class can receive singleton-compatible dependencies through its constructor. Additional services can be injected into Invoke or InvokeAsync parameters, allowing scoped services to be resolved for the current request.

99
Mid-LevelIntermediate

What is IMiddleware and how is it different from conventional middleware?

IMiddleware provides a factory-activated middleware model. A class implements IMiddleware and is registered with the dependency injection container. The framework resolves it through IMiddlewareFactory when the pipeline executes it.

100
Mid-LevelIntermediate

What are best practices for designing the ASP.NET Core middleware pipeline?

Keep the pipeline intentional and easy to read. Place centralized exception handling early, serve static files before expensive application processing when appropriate, establish routing before middleware that relies on endpoint metadata, and run authentication before authorization.