Prepare for Your .NET Core Interview with These Essential Questions
This comprehensive guide features 30 .NET Core interview questions covering basic, intermediate, and advanced topics. Designed for freshers, developers with 1-3 years of experience, and professionals with 3-6 years, these questions focus on core .NET Core concepts, practical scenarios, and real-world applications used by companies like Amazon, Zoho, and Atlassian.
Basic .NET Core Interview Questions
1. What are the key characteristics of .NET Core?
Answer: .NET Core offers flexible deployment (can be included in your app or installed side-by-side), cross-platform support (Windows, macOS, Linux), and is designed for modern cloud-native applications with high performance.[2]
2. What is the difference between app.Run() and app.Use() middleware in .NET Core?
Answer: app.Run() terminates the pipeline and sends a response directly, while app.Use() processes the request and passes it to the next middleware in the pipeline.[1]
app.Run(async context => await context.Response.WriteAsync("Hello World!"));
app.UseAuthentication(); app.UseAuthorization();
3. What is the Common Language Runtime (CLR) in .NET Core?
Answer: The CLR manages code execution, memory management, security, and exception handling. It converts Common Intermediate Language (CIL) to machine code using the Just-In-Time (JIT) compiler.[3]
4. What are the main responsibilities of the .NET Core Startup class?
Answer: The Startup class handles configuration, dependency injection, logging, lifetime management, hosting environment detection, web server integration (Kestrel), and hosted services.[1]
5. What are the three service lifetimes in .NET Core Dependency Injection?
Answer:
- Singleton: Created once for the application lifetime
- Scoped: Created once per client request
- Transient: Created each time they’re requested
[4]
6. How does configuration binding work with strongly typed classes in .NET Core?
Answer: Create classes representing configuration settings, bind them using IOptions<T> interface, and register in the DI container for type-safe access throughout the application.[1]
7. What is Kestrel in .NET Core?
Answer: Kestrel is a cross-platform web server for ASP.NET Core applications, handling HTTP requests efficiently and supporting high-performance scenarios.[1]
8. What is the difference between In-Memory caching and Distributed caching in .NET Core?
Answer:
| Aspect | In-Memory | Distributed |
|---|---|---|
| Availability | Lost on server restart | Survives individual server failures |
| Performance | Faster (memory access) | Slower (network access) |
| Scalability | Single server | Multiple servers |
[1]
9. What is the purpose of appsettings.json in .NET Core?
Answer: appsettings.json stores application configuration settings, environment variables, and connection strings in a hierarchical JSON format that’s reloadable at runtime.[1]
10. How do you enable HTTPS in .NET Core development?
Answer: Use app.UseHttpsRedirection(); in the middleware pipeline and configure development certificates with dotnet dev-certs https --trust.[1]
Intermediate .NET Core Interview Questions
11. Explain how async/await works in .NET Core with this example:
private async Task<bool> TestFunction()
{
var x = await DoesSomethingExists();
var y = await DoesSomethingElseExists();
return y;
}
Answer: The second await executes only after the first await completes. Each await yields control back to the caller until its task completes, enabling non-blocking operations.[2]
12. How would you implement logging in a .NET Core application at Zoho?
Answer: Configure logging in Program.cs or Startup.cs, inject ILogger<T> into controllers/services, and use structured logging methods like _logger.LogInformation("User {UserId} logged in", userId);[1]
13. What is the difference between IApplicationBuilder and IHostBuilder in .NET Core?
Answer: IApplicationBuilder configures the HTTP request pipeline (middleware), while IHostBuilder configures the entire host including services, logging, and hosting environment.[1]
14. How do you handle model binding in ASP.NET Core MVC?
Answer: ASP.NET Core automatically binds HTTP request data (query strings, form data, route values) to action method parameters or strongly-typed models using attributes like [FromBody], [FromQuery].[4]
15. What are Middleware components in .NET Core?
Answer: Middleware are software components assembled into an application pipeline to handle requests and responses. Each component can process requests, short-circuit the pipeline, or pass to the next component.[1]
16. How do you implement custom middleware in .NET Core?
public class CustomMiddleware
{
private readonly RequestDelegate _next;
public CustomMiddleware(RequestDelegate next) => _next = next;
public async Task InvokeAsync(HttpContext context)
{
// Custom logic before
await _next(context);
// Custom logic after
}
}
Answer: Create a class with InvokeAsync method, register with app.UseMiddleware<CustomMiddleware>(); in the pipeline.[1]
17. Explain Action Filters in ASP.NET Core MVC.
Answer: Action filters run before and after action methods execute, enabling cross-cutting concerns like authorization, caching, and logging. Implement IAsyncActionFilter or use attributes.[4]
18. How does .NET Core handle environment-specific configurations?
Answer: Use environment-specific files like appsettings.Development.json, appsettings.Production.json. Access via IWebHostEnvironment.IsDevelopment() or env.EnvironmentName.[1]
19. What is the purpose of Program.cs in .NET 6+ minimal hosting model?
Answer: Program.cs configures the host builder, services, and middleware pipeline in a single file, replacing the separate Startup.cs class for simpler application startup.[1]
20. How do you implement Health Checks in .NET Core?
Answer: Add services.AddHealthChecks(); in DI container, then app.UseHealthChecks("/health"); in pipeline. Useful for container orchestration and monitoring.[1]
Advanced .NET Core Interview Questions
21. How would Atlassian implement background services in .NET Core?
Answer: Implement IHostedService or inherit from BackgroundService, register with DI container. Example:
public class Worker : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
while (!stoppingToken.IsCancellationRequested)
{
await DoWork();
await Task.Delay(1000, stoppingToken);
}
}
}
[1]
22. Explain Finalize vs Dispose pattern in .NET Core.
Answer: Finalize is called by GC (unreliable timing), Dispose is called explicitly. Implement both in disposable pattern using IDisposable with SuppressFinalize(this).[2]
23. How do you optimize .NET Core applications for high traffic like Paytm?
Answer: Use response caching, distributed caching (Redis), async/await everywhere, connection pooling, output caching middleware, and configure Kestrel for high concurrency.[1]
24. What is the Output Caching middleware in .NET Core?
Answer: Caches responses based on cache key (URL + query string). Configure with services.AddOutputCache(); and app.UseOutputCache();. Supports VaryBy directives.[1]
25. How do you debug a 404 error in ASP.NET Core routing?
Answer: Check 1) Route registration, 2) Route constraints, 3) HTTP method matching, 4) Middleware order, 5) Controller/Action existence, 6) IDE output window for detailed errors.[4]
26. What are the advantages of .NET Core’s flexible deployment model?
Answer: Self-contained deployment, side-by-side versioning, no global framework installation required, framework-dependent or independent deployment options.[2][3]
27. How do you implement Rate Limiting in .NET Core?
Answer: Use AspNetCoreRateLimit package or built-in services.AddRateLimiter(); (NET 7+). Configure policies for IP/client-based limits with sliding windows.[1]
28. Explain how Reflection is used in .NET Core DI containers.
Answer: Reflection enables automatic dependency resolution by inspecting constructor parameters and resolving them from the service container. Used for metadata inspection and dynamic invocation.[5]
29. Scenario: Amazon needs to handle 10K concurrent users. What .NET Core optimizations would you apply?
Answer: Configure Kestrel thread pool, use AddResponseCaching(), implement distributed sessions, async database calls with EF Core, connection resiliency, and health checks.[1][3]
30. How do you create a custom Authentication handler in .NET Core?
public class CustomAuthHandler : AuthenticationHandler<CustomAuthOptions>
{
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
{
// Custom authentication logic
return Task.FromResult(AuthenticateResult.Success(ticket));
}
}
Answer: Inherit from AuthenticationHandler, implement HandleAuthenticateAsync, register scheme in DI with AddAuthentication().[1]
## Related .NET Core Topics for Further Reading
- ASP.NET Core Middleware Pipeline
- Dependency Injection Best Practices
- Performance Optimization Techniques
- Container Deployment Strategies