1. Home
  2. Docs
  3. ASP.NET Core
  4. Interview Questions
  5. SECTION 1: .NET / ASP.NET (Q1–25 with Answers)

SECTION 1: .NET / ASP.NET (Q1–25 with Answers)

1. What is the difference between .NET Framework and .NET Core?

Answer:
.NET Framework is Windows-only and older.
.NET Core (now just called .NET 6/7/8+) is cross-platform, lightweight, modular, and optimized for cloud and microservices. It has better performance and supports Linux and macOS.


2. What are the key features of ASP.NET Core?

Answer:

  • Cross-platform
  • Built-in dependency injection
  • Middleware pipeline
  • High performance
  • Cloud-ready
  • Unified MVC & Web API framework

3. Explain dependency injection in .NET.

Answer:
Dependency Injection (DI) is a design pattern where dependencies are provided to a class rather than created inside it. In ASP.NET Core, services are registered in Program.cs and injected via constructor injection. It improves testability and loose coupling.


4. What is middleware in ASP.NET Core?

Answer:
Middleware are components in the HTTP request pipeline. Each middleware handles requests and either passes them to the next component or short-circuits the pipeline.

Example: authentication, logging, exception handling.


5. How does routing work in ASP.NET Core?

Answer:
Routing maps incoming HTTP requests to controllers and actions. It uses attribute routing or conventional routing to determine which endpoint handles the request.


6. What is the difference between MVC and Razor Pages?

Answer:
MVC separates Controllers, Views, and Models.
Razor Pages is page-focused and simpler, designed for smaller applications or page-based scenarios.


7. Explain the lifecycle of an ASP.NET Core request.

Answer:

  1. Request enters Kestrel server
  2. Passes through middleware pipeline
  3. Routing selects endpoint
  4. Controller/action executes
  5. Response passes back through middleware
  6. Sent to client

8. What is Entity Framework Core?

Answer:
EF Core is an ORM that allows you to interact with databases using C# objects instead of writing raw SQL.


9. Code First vs Database First — differences?

Answer:

  • Code First: Define models in C#, database generated from code.
  • Database First: Existing database, models generated from DB schema.

10. How do you handle migrations in EF Core?

Answer:
Use:

Add-Migration MigrationName
Update-Database

Migrations track schema changes and apply them safely.


11. What is LINQ and how does it work?

Answer:
LINQ allows querying collections and databases using C# syntax. It translates queries into SQL when used with EF Core.


12. What is asynchronous programming in .NET?

Answer:
It allows non-blocking operations using async and await, improving scalability in web apps by freeing threads during I/O operations.


13. Explain async/await.

Answer:
async marks a method as asynchronous.
await pauses execution until the task completes without blocking the thread.


14. What is Task vs Thread?

Answer:
Thread = actual OS-level thread.
Task = abstraction over asynchronous work, managed by the Task Parallel Library.


15. How do you implement authentication in ASP.NET Core?

Answer:
Using middleware such as:

  • Cookie authentication
  • JWT authentication
  • ASP.NET Identity

Configured in Program.cs.


16. What is JWT authentication?

Answer:
JSON Web Token is a stateless authentication method. The server issues a signed token which the client sends with each request.


17. How do you implement role-based authorization?

Answer:
Using [Authorize(Roles = "Admin")] attribute on controllers or actions.


18. What are filters in ASP.NET Core?

Answer:
Filters run before or after controller actions. Types:

  • Authorization filters
  • Action filters
  • Exception filters
  • Result filters

19. What is the difference between IEnumerable and IQueryable?

Answer:
IEnumerable executes queries in memory.
IQueryable executes queries in the database before data is loaded.


20. How do you handle global exception handling?

Answer:
Using custom middleware or UseExceptionHandler() in the pipeline.


21. What is model binding?

Answer:
Model binding automatically maps HTTP request data to action parameters or model objects.


22. What is the difference between ViewData, ViewBag, and TempData?

Answer:

  • ViewData: Dictionary object.
  • ViewBag: Dynamic wrapper around ViewData.
  • TempData: Persists data between requests.

23. How do you configure logging in .NET?

Answer:
Using built-in logging providers configured in Program.cs or via appsettings.json.


24. What is Serilog or NLog?

Answer:
Third-party structured logging libraries offering advanced logging features like file logging, database logging, etc.


25. What is REST and how do you build REST APIs in .NET?

Answer:
REST is an architectural style using HTTP verbs (GET, POST, PUT, DELETE).
In .NET, you build REST APIs using Controllers with [ApiController] and route attributes.


How can we help?