PrepPilotPractise free

ASP.NET Core interview questions

Middleware, DI, minimal APIs, config, auth, hosting

17 questions · Kestrel · updated November 2026

Practise these as flashcards. One or two lines each; the ones you miss come back first.

Start free

Core questions

What is middleware in ASP.NET Core, and why does its order matter?

Middleware are components that process HTTP requests and responses in a pipeline. The order matters because each middleware can modify the request or response, and some (like authentication) must run before others (like authorization) to work correctly.

How do you register a service as scoped in ASP.NET Core DI?

You register a scoped service using services.AddScoped<IMyService, MyService>() in the DI container. This ensures one instance per HTTP request.

What is the difference between minimal APIs and controllers?

Minimal APIs let you define endpoints with less code, directly in Program.cs, which is great for small services. Controllers provide more structure, support for filters, and are better for larger or more complex applications.

How do you bind configuration settings to a strongly-typed class?

You use the options pattern: create a POCO class, bind it in services.Configure<T>(...), and inject IOptions<T> where needed.

Intermediate questions

Explain the difference between transient, scoped, and singleton lifetimes in DI.

Transient services are created every time they're requested, scoped services are created once per HTTP request, and singleton services are created once for the application's lifetime. Choosing the right lifetime prevents issues like memory leaks or unintended shared state.

What is a captive dependency and why is it a problem?

A captive dependency occurs when a singleton depends on a scoped or transient service. This causes the shorter-lived service to be held longer than intended, leading to bugs or memory leaks.

How do you configure JWT Bearer authentication in ASP.NET Core?

You call services.AddAuthentication().AddJwtBearer(...) in Program.cs or Startup.cs, specifying token validation parameters like issuer, audience, and signing key. Then, add the authentication and authorization middleware in the correct order.

How does model validation work with [ApiController]?

With [ApiController], model validation is automatic. If the model is invalid, the framework returns a 400 response with validation errors before the action runs.

How do you expose a health check endpoint?

You register health checks with services.AddHealthChecks() and map them with app.MapHealthChecks("/health"). This provides a standard endpoint for monitoring tools.

What is the purpose of the IOptions<T> interface?

IOptions<T> provides access to configuration-bound settings in a type-safe way, allowing you to inject configuration sections as strongly-typed objects.

Why should you configure forwarded headers when running behind a reverse proxy?

Forwarded headers like X-Forwarded-For and X-Forwarded-Proto let your app know the original client IP and protocol, which is important for logging, authentication, and generating correct URLs.

How do you handle environment-specific configuration in ASP.NET Core?

ASP.NET Core loads configuration files like appsettings.{Environment}.json based on the ASPNETCORE_ENVIRONMENT variable. You can override settings per environment and use secrets or environment variables for sensitive data.

Senior questions

How would you debug a missing authentication issue in a production ASP.NET Core app?

See the answer in the app, free

Describe how you would containerize an ASP.NET Core app for production.

See the answer in the app, free

How do you implement custom authorization policies?

See the answer in the app, free

What are the trade-offs between minimal APIs and controllers in a large project?

See the answer in the app, free

How would you add distributed tracing to an ASP.NET Core app?

See the answer in the app, free

More .NET topics