ASP.NET Core Interview Questions – Essential Guide for .NET Developers
ASP.NET Core is the go-to framework for building modern web applications and APIs with .NET. Whether you are interviewing for a backend or full-stack .NET role, these questions will help you demonstrate a deep understanding of the framework and its architecture.
Why ASP.NET Core Questions Are Critical in Interviews
Interviewers use ASP.NET Core questions to assess your ability to build scalable web applications, your understanding of middleware pipelines, dependency injection patterns, and your knowledge of modern .NET practices.
1. What Is ASP.NET Core and How Is It Different from ASP.NET?
ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern web applications. Unlike the original ASP.NET which only ran on Windows with IIS, ASP.NET Core runs on Windows, Linux, and macOS.
Key differences include cross-platform support, built-in dependency injection, a unified MVC and Web API framework, Kestrel as a lightweight web server, and a modular middleware pipeline instead of the older HttpModules and HttpHandlers.
Interview Tip: Emphasize the performance improvements. ASP.NET Core is significantly faster than ASP.NET MVC due to Kestrel and the optimized request pipeline.
2. What Is the Middleware Pipeline in ASP.NET Core?
Middleware is software assembled into the application pipeline to handle requests and responses. Each component can process the request, pass it to the next component, or short-circuit the pipeline.
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
The order of middleware registration matters. Authentication must come before authorization, and static files middleware should be registered early.
3. How Does Dependency Injection Work in ASP.NET Core?
ASP.NET Core has a built-in IoC container supporting three service lifetimes:
- Transient — New instance every time the service is requested
- Scoped — One instance per HTTP request
- Singleton — One instance for the entire application lifetime
builder.Services.AddTransient<IEmailService, EmailService>();
builder.Services.AddScoped<IUserRepository, UserRepository>();
builder.Services.AddSingleton<ICacheService, RedisCacheService>();
Interview Tip: A common mistake is registering a Scoped service inside a Singleton. This causes a captive dependency and can lead to unexpected behavior.
4. What Is Kestrel in ASP.NET Core?
Kestrel is a cross-platform, lightweight web server built into ASP.NET Core. It can be used as an edge server or behind a reverse proxy like Nginx, Apache, or IIS.
Kestrel is extremely fast. In production, use it behind a reverse proxy for SSL termination, load balancing, and static file caching.
5. What Are Minimal APIs in ASP.NET Core?
Minimal APIs were introduced in .NET 6 to simplify HTTP API creation with minimal code and no controllers required.
var app = WebApplication.CreateBuilder(args).Build();
app.MapGet("/hello", () => "Hello World!");
app.MapGet("/users/{id}", async (int id, IUserService svc) =>
await svc.GetByIdAsync(id) is var user and not null
? Results.Ok(user) : Results.NotFound());
app.Run();
6. What Is the Difference Between AddMvc, AddControllers, and AddRazorPages?
AddControllers() registers only API controllers. AddControllersWithViews() adds MVC with Razor views. AddRazorPages() adds Razor Pages. AddMvc() registers everything. For a pure Web API, use AddControllers() to keep it lean.
7. How Does Configuration Work in ASP.NET Core?
ASP.NET Core reads from multiple sources in order: appsettings.json, appsettings.{Environment}.json, environment variables, command-line arguments, and user secrets.
var conn = builder.Configuration.GetConnectionString("Default");
builder.Services.Configure<SmtpSettings>(
builder.Configuration.GetSection("SmtpSettings"));
Interview Tip: Always use the Options pattern for strongly-typed configuration instead of reading values directly.
8. What Are Filters in ASP.NET Core?
Filters run code before or after specific stages in the request pipeline. Types include Authorization, Resource, Action, Exception, and Result filters.
9. What Is the Options Pattern?
The Options pattern provides strongly-typed access to configuration sections. Three interfaces are available: IOptions<T> for singleton lifetime, IOptionsSnapshot<T> for scoped with reload, and IOptionsMonitor<T> for real-time notifications.
10. How Do You Handle Errors Globally?
Use UseExceptionHandler for production and UseDeveloperExceptionPage for development. For APIs, implement global exception middleware or use ProblemDetails for standardized error responses.
11. Startup Class in ASP.NET Core
Q: What is the Startup Class and its methods?
The Startup class configures services and the HTTP request pipeline. ConfigureServices() registers services for dependency injection. Configure() defines how the application responds to HTTP requests by setting up middleware.
12. Middleware Deep Dive
Q: How does Middleware work in ASP.NET Core?
Middleware components are chained in the app pipeline. Each can process the request, pass it to the next middleware, and process the response on the way back. The order in Program.cs matters. Built-in middleware: Authentication, Authorization, CORS, Routing, HTTPS Redirection, Static Files.
13. Middleware vs Filters
Q: What is the difference between Middleware and Filters?
Middleware operates at the application pipeline level handling every HTTP request. Filters work at MVC action level only for controller actions. Use middleware for cross-cutting concerns; use filters for MVC-specific logic.
14. MVC Filters and Execution Order
Q: What are MVC Filters and their execution order?
Four filter types: Authorization (run first), Action (before/after action), Result (before/after result), Exception (handle unhandled exceptions). Order: Authorization → Action → Result → Exception.
15. ViewData, ViewBag, and TempData
Q: What is the difference between ViewData, ViewBag, and TempData?
ViewData is a dictionary for controller-to-view data. ViewBag is a dynamic wrapper around ViewData. TempData persists data for one additional request, useful for redirects.
16. ASP.NET Core vs ASP.NET Framework
Q: What are the advantages of ASP.NET Core over ASP.NET?
Cross-platform (Windows, Linux, Mac), no framework installation dependency, better performance handling more requests, and multiple deployment options including self-contained deployment.
17. CORS (Cross-Origin Resource Sharing)
Q: What is CORS and how do you implement it?
CORS is an HTTP mechanism allowing web apps to access resources on different origins.
builder.Services.AddCors(options =>
options.AddPolicy("AllowAll", policy =>
policy.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));
app.UseCors("AllowAll");
18. Onion Architecture
Q: What is Onion Architecture?
Organizes code into concentric layers: Core (business logic), Repository/Application (services), Infrastructure (data access), and Presentation (API/UI). Dependencies flow inward — inner layers have no knowledge of outer layers.
19. API Gateway
Q: What is an API Gateway?
Sits between clients and microservices, routing requests based on policies and aggregating responses. Handles authentication, rate limiting, and load balancing. Ocelot is a popular .NET-based API Gateway.
Final Thoughts
ASP.NET Core knowledge is essential for any .NET developer. Focus on the middleware pipeline, DI lifetimes, and configuration patterns. Continue your preparation on Code Smarter. Learn Faster.