Skip to main content

Senior .NET Core Interview Questions

Curated Senior-level .NET Core interview questions for developers targeting senior positions. 27 questions available.

Last updated:

.NET Core Interview Questions & Answers

Skip to Questions

Welcome to our comprehensive collection of .NET Core interview questions and answers. This page contains expertly curated interview questions covering all aspects of .NET Core, from fundamental concepts to advanced topics. Whether you're preparing for an entry-level position or a senior role, you'll find questions tailored to your experience level.

Our .NET Core interview questions are designed to help you:

  • Understand core concepts and best practices in .NET Core
  • Prepare for technical interviews at all experience levels
  • Master both theoretical knowledge and practical application
  • Build confidence for your next .NET Core interview

Each question includes detailed answers and explanations to help you understand not just what the answer is, but why it's correct. We cover topics ranging from basic .NET Core concepts to advanced scenarios that you might encounter in senior-level interviews.

Use the filters below to find questions by difficulty level (Entry, Junior, Mid, Senior, Expert) or focus specifically on code challenges. Each question is carefully crafted to reflect real-world interview scenarios you'll encounter at top tech companies, startups, and MNCs.

Questions

27 questions
Q1:

Explain the ASP.NET Core hosting model (Host Builder + Kestrel + Startup flow).

Senior

Answer

The hosting model uses a Generic Host that configures DI, logging, configuration, environment settings, and Kestrel. Startup constructs middleware pipeline and endpoint routing. The flow is: Host ? Kestrel ? Middleware ? Routing ? Endpoint.

Quick Summary: The Generic Host (IHostBuilder) provides a unified hosting model for web apps, workers, console apps, and Windows services. It handles DI, configuration, logging, and application lifetime centrally. The older Web Host (IWebHostBuilder) was web-only. Generic Host replaced it in .NET 3.1+ as the standard for all .NET apps.
Q2:

What is Kestrel and why does ASP.NET Core use it?

Senior

Answer

Kestrel is a high-performance cross-platform server optimized for asynchronous I/O. ASP.NET Core uses it because it offers superior throughput, low memory overhead, full platform portability, and seamless integration behind reverse proxies like Nginx/IIS.

Quick Summary: Kestrel handles raw HTTP/HTTPS connections and processes requests fully within the .NET process. It's fast, cross-platform, and supports HTTP/2 and HTTP/3. Without IIS or nginx in front, Kestrel handles everything. In production, a reverse proxy handles TLS, rate limiting, and load balancing while forwarding HTTP to Kestrel internally.
Q3:

Explain Middleware and the purpose of the ASP.NET Core Request Pipeline.

Senior

Answer

Middleware components execute sequentially for every request. Each can inspect, modify, or short-circuit the pipeline. This modular pipeline replaces old HTTP modules/handlers and provides full control over request flow.

Quick Summary: Each middleware is a delegate that wraps the rest of the pipeline. When you call app.Use(async (context, next) => { ... await next(context); }), you're adding a step. Each middleware can short-circuit (return without calling next) or continue. The order is critical — authentication must come before authorization; routing before endpoint execution.
Q4:

What is Dependency Injection in ASP.NET Core and why is it built-in?

Senior

Answer

ASP.NET Core includes a first-class DI container used across the entire framework: controllers, middleware, services. It promotes testable, modular, and maintainable architecture without external frameworks.

Quick Summary: ASP.NET Core's built-in DI removes the need for external IoC containers for most use cases. It supports constructor injection for controllers, services, middleware, and Razor Pages. Registering abstractions and concrete implementations enables runtime swap of implementations — critical for unit testing with mocks.
Q5:

Explain DI lifetimes: Transient, Scoped, Singleton.

Senior

Answer

Transient: New instance each request.
Scoped: One instance per HTTP request.
Singleton: One instance for entire app lifetime.

Wrong lifetimes cause concurrency bugs, memory leaks, or stale state.

Quick Summary: Transient: fresh instance each injection — good for lightweight, stateless services. Scoped: single instance per HTTP request — EF Core DbContext is the classic example. Singleton: one shared instance for the app's lifetime — should be thread-safe. Never capture Scoped or Transient services in a Singleton — they'll be shared across all requests incorrectly.
Q6:

How does Configuration work in ASP.NET Core?

Senior

Answer

The configuration system merges layered sources: appsettings.json, environment-specific JSON, env variables, command-line args, user secrets, and external sources. Binding and hot-reload supported.

Quick Summary: Configuration providers layer their values: appsettings.json base → environment-specific JSON → environment variables → command-line args. Each layer can override previous ones. Providers implement IConfigurationProvider. You can add custom providers (database, Vault, etcd) by calling builder.Configuration.Add(yourProvider).
Q7:

What is the purpose of IOptions, IOptionsSnapshot, and IOptionsMonitor?

Senior

Answer

IOptions: Singleton config.
IOptionsSnapshot: Reload per request.
IOptionsMonitor: Real-time config with change notifications.

Quick Summary: IOptions is singleton — reads config at startup. IOptionsSnapshot is scoped — reflects config changes between requests (requires file-based config with reloadOnChange: true). IOptionsMonitor is singleton with a reactive change callback — use it in singletons that need to react to configuration changes without restarting.
Q8:

What is Routing in ASP.NET Core?

Senior

Answer

Endpoint Routing maps URLs to endpoints. It performs early URL matching, supports metadata, improves performance with route tables, and centralizes routing logic.

Quick Summary: Routing maps URL patterns to endpoint handlers. UseRouting() does the matching. UseEndpoints() / MapControllers() / MapGet() defines and executes the endpoints. Attribute routing ([Route("api/[controller]")]) gives precise URL control per action. Route constraints ({id:int:min(1)}) enforce parameter types and values at routing time.
Q9:

What is Model Validation and how does it work?

Senior

Answer

Validation runs after binding and populates ModelState with errors. Action logic executes only after validation passes. Supports Data Annotations, custom validators, and IValidatableObject.

Quick Summary: Data annotations validate model properties after binding. [Required] prevents nulls/empties; [StringLength] limits character count; [Range] checks numeric bounds. ModelState.IsValid tells you if all passed. Return 400 with ModelState if invalid. For complex rules spanning multiple fields, implement IValidatableObject.Validate() on the model class.
Q10:

What are Filters and why are they important?

Senior

Answer

Filters run at specific pipeline stages: Authorization, Resource, Action, Exception, and Result filters. They implement cross-cutting concerns like logging, caching, or auditing.

Quick Summary: Filters are pipeline hooks for cross-cutting concerns. Authorization Filters run first and can short-circuit unauthenticated requests. Action Filters run before/after the action — log parameters, validate headers. Result Filters wrap result execution — modify output. Exception Filters handle unhandled exceptions from actions. All can be scoped globally, per-controller, or per-action.
Q11:

Explain Layouts, Partial Views, and View Components.

Senior

Answer

Layouts: Master UI shell.
Partial Views: Shared HTML fragments.
View Components: Reusable components with logic + view.

Quick Summary: _Layout.cshtml defines the shared page structure (header, nav, CSS imports). Views call @RenderBody() in the layout to inject their content. Partial Views: @Html.Partial("_Card", model) or tag helper — stateless HTML fragment. ViewComponents: @await Component.InvokeAsync("MyWidget") — runs logic and renders a sub-view with its own DI and async support.
Q12:

What is TempData and how is it different from ViewData/ViewBag?

Senior

Answer

ViewData/ViewBag: For same request only.
TempData: Persisted across redirects using cookies or session. Ideal for one-time messages.

Quick Summary: TempData survives exactly one redirect. Set it before RedirectToAction(); read it in the destination action or view. ViewData is a dictionary — controller sets it, view reads it within one request. ViewBag is dynamic syntax over ViewData (ViewBag.Title = "X" is ViewData["Title"] = "X"). TempData uses cookie or session; the others don't persist.
Q13:

Explain the ASP.NET Core hosting model (Host Builder + Kestrel + Startup flow).

Senior

Answer

ASP.NET Core uses a unified Host that manages configuration, logging, DI, environment, and pipeline. The flow:

  • Host initializes runtime and services
  • Kestrel web server starts
  • Configuration sources load
  • Services added to DI
  • Middleware pipeline built
  • The app starts listening for HTTP requests

The unified model gives fine-grained control of every system layer.

Quick Summary: The Generic Host handles all .NET app types — web, worker, console, Windows service. Builder.Services registers dependencies; builder.Configuration reads config sources; builder.Logging adds log providers. Build() creates the host; Run() starts it. WebApplication (minimal API) wraps this in .NET 6+ with an even simpler API.
Q14:

Explain Middleware and the ASP.NET Core Request Pipeline.

Senior

Answer

Middleware are sequential components that inspect, transform, route, or short-circuit HTTP requests. Each middleware can:

  • Read request
  • Modify response
  • Call next middleware
  • Handle the response entirely

The pipeline is flexible, efficient, and replaces legacy HTTP modules/handlers.

Quick Summary: Request enters → runs through middleware in order: exception handler → HSTS → static files → routing → auth → authorization → endpoint. Response returns through middlewares in reverse. Each middleware calls next() to continue or returns early to short-circuit. The pipeline is built in Program.cs with app.Use*() methods.
Q15:

What is Dependency Injection in ASP.NET Core and why is it built-in?

Senior

Answer

ASP.NET Core includes a built-in DI container to unify object creation, lifecycle management, and dependency resolution. DI improves maintainability, testing, modularity, and supports the framework's extensible design.

Quick Summary: ASP.NET Core's container (IServiceCollection) enables constructor injection everywhere — controllers, Razor Pages, middleware, ViewComponents. Register via services.AddScoped(). The framework resolves the dependency graph automatically at runtime. This eliminates manual new() calls and enables testability by swapping implementations.
Q16:

What is Configuration in ASP.NET Core and how does it work?

Senior

Answer

ASP.NET Core configuration is hierarchical and supports multiple providers:

  • appsettings.json
  • Environment-specific files
  • Env variables
  • Command-line arguments
  • Secrets / Key Vault

Values bind to strongly-typed classes and support reload-on-change.

Quick Summary: Configuration reads from multiple sources layered: JSON → environment variables → command-line → secrets. Each source can override previous values. IConfiguration is the unified interface. Bind sections to strongly-typed POCOs with services.Configure(config.GetSection("MySection")) for type-safe access throughout the app.
Q17:

What is the purpose of IOptions, IOptionsSnapshot, and IOptionsMonitor?

Senior

Answer

  • IOptions: Singleton configuration, loaded once.
  • IOptionsSnapshot: Per-request config, refreshed each request.
  • IOptionsMonitor: Live config with change notifications.
Quick Summary: Three options interfaces for different scenarios: IOptions never changes after startup (singleton). IOptionsSnapshot re-reads per request — good for config files with reloadOnChange: true. IOptionsMonitor notifies subscribers immediately when config changes — best for singletons that need live updates without restart.
Q18:

What is Model Binding?

Senior

Answer

Model Binding converts HTTP inputs (query, route, form, body, headers) into strongly-typed .NET objects. It abstracts away manual parsing.

Quick Summary: Model binding maps HTTP request data to action parameters automatically. ASP.NET Core reads [FromBody] from the request body (JSON), [FromRoute] from route segments, [FromQuery] from query string, [FromForm] from form data. Without explicit attributes, it uses default sources based on parameter type (complex types default to body, simple types to query).
Q19:

What are Filters and why are they important?

Senior

Answer

Filters enable cross-cutting concerns such as logging, caching, authorization, and exception handling. Types include authorization, resource, action, exception, and result filters.

Quick Summary: Filters are AOP-style hooks. Authorization Filters gate access. Action Filters run business logic before/after action (logging, performance measurement). Result Filters modify responses (add headers, compress). Exception Filters catch unhandled action exceptions for consistent error formatting. Filters are more expressive than middleware for MVC-specific concerns.
Q20:

Explain Layouts, Partial Views, and View Components.

Senior

Answer

  • Layouts: Master templates for shared UI.
  • Partials: Reusable HTML fragments.
  • View Components: Encapsulated logic + view, ideal for widgets.
Quick Summary: Layout: _Layout.cshtml wraps views with shared chrome. Partial Views: reusable HTML fragments rendered inline with . ViewComponents: smart, self-contained widgets that run async logic (inject services, call DB) and render their own view — like a mini-controller. Best for dynamic sidebars, notification badges, and complex UI sections.
Q21:

What are Tag Helpers?

Senior

Answer

Tag Helpers enable server-side processing of HTML elements. They provide compile-time checking, IntelliSense, clean syntax, and strong typing.

Quick Summary: Tag Helpers process HTML elements server-side during view rendering. generates a correctly-named input with validation attributes. They look like plain HTML and work with HTML IntelliSense. Much cleaner than @Html.TextBoxFor(m => m.Email) HTML Helper syntax, which is C#-centric and harder to style.
Q22:

What is TempData and how is it different from ViewData/ViewBag?

Senior

Answer

ViewData/ViewBag: Per-request data.

TempData: Persists across redirects until consumed. Backed by cookies or session.

Quick Summary: TempData persists across a redirect — set before redirecting, read in destination. Useful for success/error messages after form submissions. ViewData: dictionary for current request (controller sets, view reads). ViewBag: dynamic property syntax over ViewData. TempData uses either cookie or session backend. All three are for controller-to-view communication.
Q23:

How does ASP.NET Core handle static files and why is middleware important?

Senior

Answer

The Static Files middleware serves CSS/JS/images directly without MVC involvement. It must be placed early in the pipeline to bypass unnecessary routing and processing.

Quick Summary: Static Files middleware intercepts matching file requests before routing and serves them directly from wwwroot — no controller, no auth required. It must be first in the pipeline so static assets (CSS, JS) are available to unauthenticated users. Without it, every static file request would go through the full MVC pipeline unnecessarily.
Q24:

Difference between Generic Host and Web Host.

Senior

Answer

Generic Host is the unified hosting model supporting all app types (web, workers, gRPC). Web Host was only for web apps. Generic Host centralizes DI, logging, config, and enables multi-service hosting.

Quick Summary: Generic Host is the modern, unified host for all .NET app types — web, worker services, console apps. Web Host was the original ASP.NET Core-specific host, now superseded. In .NET 6+, WebApplication.CreateBuilder() uses Generic Host internally. Both support DI, configuration, and logging — but Generic Host is the standard going forward.
Q25:

Explain ASP.NET Core Application Lifetime events.

Senior

Answer

Lifetime events:

  • ApplicationStarted
  • ApplicationStopping
  • ApplicationStopped

They allow warm-ups, cache initialization, graceful shutdowns, and log flushing.

Quick Summary: IHostApplicationLifetime provides hooks: ApplicationStarted fires when the host is ready (warm caches, connect to message brokers). ApplicationStopping fires when shutdown is requested but before it completes (drain connections, stop background work). ApplicationStopped fires when everything is done. Inject it into any service that needs lifecycle awareness.
Q26:

What is Web Root vs Content Root in ASP.NET Core?

Senior

Answer

Content Root: Base path for code, views, and config files.

Web Root: Public folder (wwwroot) exposed to the web for static files.

This separation prevents accidental exposure of sensitive project files.

Quick Summary: Content Root is the app's home directory — contains appsettings.json, Views, Program.cs output. Web Root (wwwroot by default) is the public directory served to browsers — CSS, JS, images. Separating them ensures the app's source, configs, and secrets are never accidentally served as static files by the Static Files middleware.
Q27:

What happens inside the CLR from compilation to execution?

Senior

Answer

The CLR pipeline includes Roslyn compilation to IL, metadata creation, IL loading, verification, JIT compilation, and optimized native execution through tiered compilation and RyuJIT. Execution runs under GC, exception handling, and runtime type safety. Supports JIT, AOT, ReadyToRun, and NativeAOT modes.

Quick Summary: When you write C#, Roslyn compiles it to IL (Intermediate Language), stored in a .dll assembly. The CLR loads the assembly, verifies the IL, and the JIT compiler converts it to native machine code on first execution. The GC manages memory automatically — allocating on the managed heap and reclaiming unreachable objects.

Curated Sets for .NET Core

No curated sets yet. Group questions into collections from the admin panel to feature them here.

Ready to level up? Start Practice