ASP.NET Core Interview Questions and Answers
ASP.NET Core interview questions — the request pipeline and middleware, built-in dependency injection, configuration, hosting, Kestrel, Web API and EF Core integration.
- 01 How does configuration work in ASP.NET Core? Configuration is built from an ordered set of providers — appsettings.json, appsettings.{Environment}.json, user…
- 02 What is the Options pattern, and what is the difference between IOptions, IOptionsSnapshot and IOptionsMonitor? The Options pattern binds a configuration section to a strongly typed class and injects it. IOptions<T> — singleton,…
- 03 What are environments in ASP.NET Core? An environment is a named runtime context — Development, Staging, Production (or your own) — set by the…
- 04 What is a hosted service / BackgroundService in ASP.NET Core? IHostedService (usually via the BackgroundService base class) runs background work tied to the app's lifetime — queue…
- 05 What are Minimal APIs, and how do they compare to controllers? Minimal APIs define HTTP endpoints as lambdas directly on the app — app.MapGet("/orders/{id}", (int id, IOrderService…
- 06 How do you register and resolve multiple implementations of the same interface in ASP.NET Core DI? Register each implementation against the interface; the container collects them. Inject IEnumerable<INotifier> to get…
- 07 What is the difference between authentication and authorization in ASP.NET Core? Authentication establishes who the caller is — it validates a cookie, JWT or other credential and builds a…
- 08 What is JWT authentication and how does it work? A JWT is a signed token with three base64url parts — header, payload (claims), signature. After login the server…
- 09 What is IHttpClientFactory and why should you use it? IHttpClientFactory manages the lifetime of HttpClient's underlying HttpMessageHandler, pooling and rotating them. It…
- 10 What is the difference between response caching and output caching in ASP.NET Core? Response caching sets HTTP cache headers (Cache-Control) and honours them via a middleware cache — it relies on the…
- 11 What is model binding in ASP.NET Core, and what are the binding sources? Model binding maps values from the HTTP request onto your action's parameters. Sources: [FromRoute], [FromQuery],…
- 12 What is the role of Program.cs (and the old Startup class) in ASP.NET Core? Program.cs is the application's entry point: it builds the host, registers services in the DI container…
- 13 How does logging work in ASP.NET Core? Logging is built in: inject ILogger<T> and call _logger.LogInformation(...). It's provider-based — Console, Debug,…
- 14 What is the difference between app.Use, app.Run and app.Map? app.Use adds middleware that can call next() to continue the pipeline (or not). app.Run adds a terminal middleware…
- 15 What is policy-based authorization, and how does it compare to role-based? Role-based ([Authorize(Roles = "Admin")]) checks a single claim value. Policy-based authorization names a rule…
- 16 How does rate limiting work in ASP.NET Core? The built-in rate limiter (.NET 7+) is middleware — AddRateLimiter + UseRateLimiter — with four algorithms: fixed…
- 17 What are health checks in ASP.NET Core? Health checks expose an endpoint (/health) that reports whether the app and its dependencies are working. Register…
- 18 What is the standard resilience handler / Polly, and what does it give you? Polly is a resilience library; AddStandardResilienceHandler() (Microsoft.Extensions.Http.Resilience) wires a sensible…
- 19 What is the middleware ordering rule, and what breaks if you get it wrong? Middleware runs in the order you add it, and the response unwinds in reverse. The rules that matter: exception…
- 20 What is the difference between AddControllers, AddControllersWithViews, AddRazorPages and AddMvc? AddControllers() — controllers + API features only (for a Web API). AddControllersWithViews() — adds Razor views and…
- 21 What is HttpContext, and why shouldn't you store or use it outside a request? HttpContext holds everything about the current request/response — User, Request, Response, Items, request services.…
- 22 How do you configure JSON serialization in ASP.NET Core (System.Text.Json)? ASP.NET Core uses System.Text.Json by default. Configure it with AddControllers().AddJsonOptions(o => { ... }) —…
- 23 Why can't you inject a scoped service into the constructor of custom middleware? Conventional middleware is instantiated once at startup (effectively a singleton), so injecting a scoped service like…
- 24 What is the generic host, and how does it differ from the web host? The generic host (IHost) provides DI, configuration, logging and a lifetime for any .NET app — including non-web…
- 25 How do you handle CSRF / anti-forgery for a SPA calling an ASP.NET Core API? If the SPA authenticates with a bearer token in a header (not a cookie), classic CSRF doesn't apply — the browser…
- 26 What lifetime should you register a repository, a service, and a cache? Repository / unit-of-work / anything touching DbContext → Scoped (matches the request-scoped context). Stateless…
- 27 What is the difference between Data Annotations validation and FluentValidation? Data Annotations ([Required], [Range]) are attributes on the model — simple, built-in, run automatically.…
- 28 How does ASP.NET Core serve static files, and how do you cache them? UseStaticFiles() serves files from wwwroot. Place it early in the pipeline (before routing/auth) so assets skip…
- 29 What is the Options validation pattern, and why validate configuration on startup? Bind config to an options class and validate it:…
- 30 What is ASP.NET Core? ASP.NET Core is a free, open-source, cross-platform framework for building web apps, APIs and real-time services on…
- 31 What is the difference between ASP.NET MVC and ASP.NET Core? ASP.NET MVC 5 runs only on the Windows .NET Framework, is hosted in IIS through System.Web, and needs third-party…
- 32 What is middleware in ASP.NET Core? Middleware is a component that sits in the request pipeline. Each piece of middleware receives the HttpContext, can do…
- 33 Explain the ASP.NET Core request pipeline. A request enters through Kestrel, is handed to the middleware pipeline as an HttpContext, and passes through each…
- 34 What is Kestrel in ASP.NET Core? Kestrel is the default, cross-platform web server built into ASP.NET Core. It is a fast, lightweight HTTP server that…
- 35 What is Dependency Injection in ASP.NET Core? Dependency Injection (DI) is a design technique where a class receives the objects it depends on from the outside —…
- 36 What is loose coupling? Loose coupling means a class depends on what another component does (an abstraction) rather than how it does it (a…
- 37 What is Inversion of Control (IoC)? Inversion of Control is a principle where the flow of control — who creates objects, who calls whom — is handed to a…
- 38 What are service lifetimes in ASP.NET Core? A service lifetime controls how long the container keeps and reuses an instance. There are three: Transient — a new…
- 39 What is the difference between Transient, Scoped and Singleton? Transient: new instance on every injection — most short-lived. Scoped: one instance per request, shared within that…
- 40 Why is DbContext registered as Scoped? DbContext is registered as Scoped because it is a lightweight, stateful, not thread-safe unit-of-work. One instance…
- 41 What is a captive dependency? A captive dependency is when a longer-lived service holds a reference to a shorter-lived one, “capturing” it and…
- 42 How do you run background work in ASP.NET Core? Implement IHostedService, or more commonly inherit BackgroundService and override ExecuteAsync(CancellationToken…
- 43 What does it mean for a service to be stateless, and why does it matter? A stateless service keeps no client-specific data in its own memory between requests — everything needed is in the…
- 44 What is the difference between session-based auth and token-based auth? Session auth — the server creates a session, stores it server-side, and gives the client a session-id cookie; each…
- 45 A deployment has broken production. Walk me through what you do. Stabilise first, diagnose second. Confirm the blast radius, roll back to the last known-good version (or shift traffic…
- 46 A read-heavy endpoint is hammering the database. How do you add caching safely? Confirm the data tolerates staleness and by how much. Pick the layer — output caching for whole responses, a…
- 47 Your app depends on a third-party API that is slow and sometimes down. How do you make your app resilient? Wrap the calls with resilience policies: a sensible timeout, retries with backoff + jitter for transient failures, a…
- 48 An API endpoint is fast in testing but slow under production load. How do you investigate? Reproduce with realistic concurrency, then use data — server metrics (CPU, memory, GC, thread-pool queue), request…
- 49 You get an intermittent NullReferenceException in production that you can't reproduce locally. How do you approach it? Get the exact stack trace and a correlation ID from structured logging, and identify the line and the reference that's…
No questions match those filters
Try removing a filter or .
About these ASP.NET Core questions
ASP.NET Core interviews centre on two things: the request pipeline and the built-in dependency injection container. If you can explain how middleware is ordered and short-circuited, and how AddTransient, AddScoped and AddSingleton differ (and why getting them wrong causes captive-dependency bugs), you have covered most of what a mid-level interview will probe.
From there, expect configuration and options, hosting and Kestrel, minimal APIs vs controllers, authentication/authorization, and how EF Core's DbContext fits the scoped lifetime. The Dependency Injection chain in this section walks the exact follow-up sequence many interviewers use.