All subjects.NET · 39 questions · 9 junior / 19 mid / 11 senior

ASP.NET Core & .NET quiz and interview questions

ASP.NET Core interviews focus on how a request flows through the app (middleware), how services are created (dependency injection lifetimes), how data is loaded (EF Core) and the bugs that only show up in production — wrong middleware order, N+1 queries and singleton DbContexts. Test yourself below.

ASP.NET Core & .NET quiz39 questions in the bank · 10 per round
Level
Question type
Mode

ASP.NET Core & .NET: key concepts

Middleware pipeline
Each request passes through middleware in the order you register them in Program.cs (routing, authentication, authorization, endpoints). Order matters: authentication must run before authorization.
DI lifetimes
Transient: a new instance every time. Scoped: one per HTTP request. Singleton: one for the whole app. Never inject a scoped service (like DbContext) into a singleton.
EF Core loading
Use Include() or a Select projection to load related data in one query. Lazy loading in a loop causes N+1 queries. Use AsNoTracking() for read-only queries.
Configuration
Settings come from appsettings.json, appsettings.{Environment}.json, user secrets, environment variables and the command line — later sources override earlier ones.
Background work
BackgroundService (IHostedService) runs long-lived jobs inside the app, such as queues or scheduled tasks, with proper start/stop handling.
HttpClient
Use IHttpClientFactory instead of new HttpClient() per call to avoid socket exhaustion and stale DNS.

All 39 ASP.NET Core & .NET questions with answers

Try each one first, then open the answer. Making a class test? Use the test maker.

  1. juniorConcepts

    What is middleware in ASP.NET Core?

    • A. A database layer
    • B. Components in a pipeline that handle each request and response
    • C. A front-end framework
    • D. A type of controller
    Show answer

    B. Components in a pipeline that handle each request and response — Middleware are chained components (logging, auth, routing…). Each can act on the request, call the next one, and act on the response.

  2. juniorConcepts

    A service registered with AddScoped is created…

    • A. Once for the whole app
    • B. Every time it's requested
    • C. Once per HTTP request
    • D. Once per user
    Show answer

    C. Once per HTTP request — Scoped = one instance per request (per DI scope). DbContext is registered as scoped by default.

  3. midConcepts

    What is the problem with injecting a scoped service into a singleton?

    • A. None
    • B. The scoped service is captured and lives for the whole app (captive dependency)
    • C. It doubles memory
    • D. The singleton becomes scoped
    Show answer

    B. The scoped service is captured and lives for the whole app (captive dependency) — The singleton keeps the first scoped instance forever, e.g. one DbContext shared across all requests and threads. ASP.NET Core's scope validation throws in Development for this reason.

  4. midFind the bug

    What is wrong with this Program.cs snippet?

    app.UseRouting();
    app.UseAuthorization();
    app.UseAuthentication();
    app.MapControllers();
    • A. Nothing
    • B. Authentication must come before authorization
    • C. UseRouting must be last
    • D. MapControllers must come first
    Show answer

    B. Authentication must come before authorization — Authorization needs to know who the user is, so UseAuthentication() has to run first. In this order, [Authorize] endpoints see an anonymous user.

  5. midConcepts

    When should you use AsNoTracking() in EF Core?

    • A. When you will update the entities
    • B. For read-only queries, to skip change tracking and run faster
    • C. Never in production
    • D. Only with stored procedures
    Show answer

    B. For read-only queries, to skip change tracking and run faster — Tracking keeps a snapshot of every loaded entity for SaveChanges. For lists or reports you won't modify, AsNoTracking() saves memory and CPU.

  6. midFind the bug

    With lazy loading on, what's the problem here?

    var orders = db.Orders.ToList();
    foreach (var o in orders)
        Console.WriteLine(o.Customer.Name);
    • A. Compile error
    • B. One extra query per order (N+1 queries)
    • C. Customer is always null
    • D. Nothing — it's efficient
    Show answer

    B. One extra query per order (N+1 queries) — Each o.Customer access runs a separate query: 1 for orders + N for customers. Use .Include(o => o.Customer) or project only the fields you need.

  7. juniorConcepts

    What is Kestrel?

    • A. A logging library
    • B. ASP.NET Core's built-in cross-platform web server
    • C. An ORM
    • D. A testing tool
    Show answer

    B. ASP.NET Core's built-in cross-platform web server — Kestrel is the default web server inside every ASP.NET Core app. It's often placed behind a reverse proxy like IIS or Nginx in production.

  8. seniorConcepts

    What is BackgroundService (IHostedService) used for?

    • A. Rendering views
    • B. Running long-lived background jobs inside the app with clean start/stop
    • C. Hosting static files
    • D. Replacing controllers
    Show answer

    B. Running long-lived background jobs inside the app with clean start/stop — Good for queue consumers, scheduled clean-ups or polling jobs. The host starts it with the app and signals cancellation on shutdown.

  9. midConcepts

    A setting exists in appsettings.json and as an environment variable. Which value wins by default?

    • A. appsettings.json
    • B. The environment variable
    • C. Whichever is shorter
    • D. The app throws an error
    Show answer

    B. The environment variable — The default builder adds environment variables after the JSON files, and later providers override earlier ones. Command-line args override both.

  10. seniorConcepts

    Why use IHttpClientFactory instead of new HttpClient() on every call?

    • A. It's required by law
    • B. It avoids socket exhaustion and handles DNS changes by pooling handlers
    • C. It makes requests synchronous
    • D. It encrypts traffic
    Show answer

    B. It avoids socket exhaustion and handles DNS changes by pooling handlers — Creating and disposing HttpClient per request leaves sockets in TIME_WAIT. The factory reuses handlers and rotates them so DNS changes are picked up.

More subjects

Need software for your business instead? I'm an AI automation & full-stack developer — see what I build.

Chat on WhatsApp