44 Most Commonly Asked ASP.NET Core Interview Questions and Answers (2025)

Blog / 44 Most Commonly Asked ASP.NET Core Interview Questions and Answers (2025)
blog image

ASP .NET Core is the lightweight, high-performance engine powering modern web APIs and full-stack apps.

Understanding its middleware pipeline, dependency-injection model, and cross-platform hosting nuances equips you to craft faster, cleaner services, as well as the ability to show off to your interviewer.

Q1.

What is ASP.NET Core?

Junior
  • ASP.NET Core is an open-source, cross-platform framework for building modern, cloud-based, and internet-connected applications.
  • A significant aspect of ASP.NET Core is its unification of the Model-View-Controller (MVC) pattern and Web API functionalities into a single cohesive model.This integration provides developers with a flexible and consistent approach for building both user interfaces and backend services.
  • It is a redesign of ASP.NET, with architectural changes that make it more modular, lightweight, and scalable.
Q2.

Explain the difference between ASP.NET Core and ASP.NET Framework.

Junior
  • ASP.NET Core is a lightweight, fully open-source, cross-platform successor to the Windows-only ASP.NET Framework.
  • Built on the modular .NET Core runtime, it delivers better performance, unifies MVC and Web API, and replaces XML-heavy configuration with simple, code-based options.
  • In contrast, the classic ASP.NET Framework is larger, tied to Windows, and relies on the full .NET runtime.
Q3.

What is the purpose of the Program class?

Junior
  • The Program.cs class serves as the entry point for an ASP.NET Core application.
  • It contains the static void Main() function, which is the first code to be executed when the application starts. This class is responsible for configuring and building the web host, which is the foundation for serving HTTP requests.
Q4.

Explain the concept of middleware in ASP.NET Core. Can you provide an example of how to create custom middleware?

Junior
  • Middleware in ASP.NET Core is components that are assembled into the request pipeline to handle requests and responses.
  • Custom middleware can be created by implementing the IMiddleware interface or using a delegate.
  • For example, to create a custom middleware using a delegate, you can use app.Use in the Configure method of the Startup class.
Q5.

What is Dependency Injection, and how is it implemented in ASP.NET Core?

Junior
  • Dependency Injection is a design pattern used to achieve loose coupling and increase testability by injecting dependencies into a class instead of creating them within the class.
  • In ASP.NET Core, DI is built into the framework, and you can use the built-in container or replace it with your preferred container.

Don't let one question ruin your next technical interview...

Q6.

Describe the role of the Startup class in ASP.NET Core.

Junior
  • The Startup class is a fundamental part of an ASP.NET Core application. It contains two important methods:
    • ConfigureServices: This method is used to configure services such as dependency injection, logging, and other application services.
    • Configure: This method is used to configure the HTTP request pipeline, including middleware, routing, and error handling.
Q7.

Explain the request processing pipeline in ASP.NET Core.

Junior
  • In ASP.NET Core, every HTTP request passes through a configurable middleware pipeline, a chain of components that each perform a task (e.g., authentication, logging, routing, serving static files) and then invoke the next link.
  • The same chain runs in reverse for the response. Grasping this flow is key to understanding how ASP.NET Core processes and returns web requests.
Q8.

What is Razor Pages in ASP.NET Core?

Junior
  • Razor Pages is a page-based programming model in ASP.NET Core for building web UI.
  • It combines the benefits of MVC and Web Forms, providing a simpler syntax for building pages with code-behind files.
  • It's particularly useful for building small to medium-sized web applications.
Q9.

How do you handle configuration in ASP.NET Core?

Junior
  • Configuration in ASP.NET Core is typically handled through the appsettings.json file, environment variables, command-line arguments, and other configuration providers.
  • The IConfiguration interface provides access to these configuration sources, and settings can be injected into services using dependency injection.
Q10.

What is the purpose of the wwwroot folder?

Junior
  • The appsettings.json file serves as a central location for storing configuration settings for an ASP.NET Core application.
  • This includes various settings that govern the application's behavior, such as database connection strings, logging levels, and custom application-specific configurations.
  • Understanding configuration is important for managing application behavior across different environments.
Q11.

What are the roles of Model, View, and Controller in ASP.NET Core MVC?

Mid
  • Model: C# classes that store data and encapsulate business logic.
  • View: .cshtml files that turn model data into HTML for the browser.
  • Controller: Handles HTTP requests, uses the model to process or update data, then chooses a view to render.
Q12.

What is Model Binding in ASP.NET Core?

Mid
  • Model binding automatically maps HTTP request data, route values, query strings, form fields, or body content, to the parameters of an action method, converting raw strings into the appropriate .NET types so the action can work with them directly.
Q13.

What is the purpose of the appsettings.json file in an ASP.NET Core application?

Mid
  • The appsettings.json file is used for configuration in ASP.NET Core. It allows developers to store application settings in a structured format, including key-value pairs.
  • The settings can be accessed using the IConfiguration interface, and the values can be overridden based on the environment (development, staging, production) or through other configuration providers.
Q14.

Differentiate between app.Run and app.Use in middleware configuration.

Mid
Use app.Use for components that may defer to subsequent middleware; use app.Run for self-contained handlers that should finish the response.
  • app.Use adds non-terminal middleware:
  • app.Run registers terminal middleware:
Q15.

What is a Request delegate in ASP.NET Core?

Mid
  • A request delegate is the core unit of ASP.NET Core’s middleware pipeline, a function that takes an HttpContext, processes it, and (optionally) calls the next delegate.
  • Middleware stacks these delegates, so each one can run logic before/after invoking the next, together completing the request-response cycle.
Q16.

How does ASP.NET Core handle authentication and authorization?

Mid
  • ASP.NET Core provides a flexible and extensible authentication and authorization system.
  • Authentication is the process of validating the identity of a user, while authorization is the process of determining what actions a user is allowed to perform.
  • ASP.NET Core supports various authentication providers, such as cookies, JWT, and external providers (Google, Facebook). Authorization is achieved using attributes like Authorize on controllers or action methods.
Q17.

How does ASP.NET Core handle state management? Explain the differences between TempData, ViewData, and ViewBag.

Mid
  • ASP.NET Core supports various mechanisms for state management.
  • TempData is used to pass data between requests, and it is stored for a short duration (usually until the next request).
  • ViewData and ViewBag are used to pass data from controllers to views. The key difference is that ViewData is a dictionary, and ViewBag is a dynamic property bag. However, both are used for similar purposes.
Q18.

What are the different service lifetimes in ASP.NET Core?

Mid
  • In ASP.NET Core, when registering services with the dependency injection container, you can specify their lifetime. The three primary lifetimes are Transient, Scoped, and Singleton.
    • A Transient service is created every time it's requested.
    • A Scoped service is created once per request (e.g., per HTTP request in a web application).
    • A Singleton service is created only once during the entire application lifetime.
Q19.

How can you handle cross-origin resource sharing (CORS) in an ASP.NET Core application?

Mid
  • CORS can be configured in an ASP.NET Core application using the Microsoft.AspNetCore.Cors package. In the Startup class, the ConfigureServices method can be used to add CORS services, and the Configure method can be used to configure CORS policies. This allows you to specify which origins, methods, and headers are allowed for cross-origin requests.
Q20.

Explain the differences between Inversion of Control (IoC) and Dependency Injection (DI).

Mid
  • Inversion of Control (IoC) is a broader design principle where the control flow of a program is inverted – instead of a component controlling the flow, it delegates control to a framework or container.
  • Dependency Injection (DI) is a specific implementation of IoC, focusing on providing a way to inject dependencies into a class from an external source. In other words, DI is a way to achieve IoC.
Q21.

How does ASP.NET Core support logging, and what are the different log levels available?

Mid
  • ASP.NET Core has a built-in logging framework that supports various log providers (Console, Debug, EventSource, etc.). The available log levels are:
    • Trace
    • Debug
    • Information
    • Warning
    • Error
    • Critical
  • Developers can use the ILogger interface to log messages at different levels throughout the application.
Q22.

What is the purpose of the async and await keywords in C#? How are they used in ASP.NET Core?

Mid
  • async and await are used to write asynchronous code in C#. The async keyword is used to define a method as asynchronous, and await is used to asynchronously wait for a task to complete without blocking the thread.
  • In ASP.NET Core, asynchronous programming is commonly used to improve the scalability of web applications by allowing the server to handle more requests concurrently without blocking threads.
Q23.

Explain the concept of middleware pipeline termination in ASP.NET Core. How can you terminate the pipeline and short-circuit further processing?

Mid
  • Middleware pipeline termination occurs when a middleware component produces a response without invoking the next middleware in the pipeline. This is often done using the HttpResponse object.
  • For example, calling context.Response.StatusCode = 404 followed by return will terminate the pipeline and send a 404 response without invoking subsequent middleware.
Q24.

What is the purpose of the app.UseExceptionHandler method in ASP.NET Core, and how can it be used to handle errors in the application?

Mid
  • app.UseExceptionHandler configures middleware to catch unhandled exceptions in the application and generate an error response.
  • This is useful for providing a consistent way to handle errors and present user-friendly error pages. Typically, you would use this middleware to log errors and display an appropriate error page to users.
Q25.

What is the purpose of the AllowAnonymous attribute in ASP.NET Core, and when would you use it in your controllers or action methods?

Mid
  • The AllowAnonymous attribute is used to specify that an action or controller should be accessible to unauthenticated users. By default, ASP.NET Core requires authentication for all requests.
  • Using AllowAnonymous on specific actions allows public access, even when authentication is required globally.
Q26.

How does ASP.NET Core support data validation, and what are the validation attributes available in the framework?

Mid
  • ASP.NET Core supports data validation through model validation. Model validation is performed automatically during model binding.
  • Validation attributes, such as Required, StringLength, and RegularExpression, can be applied to model properties to define validation rules. Additionally, developers can create custom validation attributes to enforce specific validation logic.
Q27.

Explain the purpose of the ConfigureServices method in the Startup class. How is it used to configure services in an ASP.NET Core application?

Mid
  • The ConfigureServices method in the Startup class is used to configure services for dependency injection in an ASP.NET Core application. It is where you register application services, configure options, and set up the dependency injection container.
  • Services registered here are available throughout the application, and it's a crucial step in the application's initialization.
Q28.

What is the purpose of the app.UseHttpsRedirection middleware, and how can it be configured to enforce HTTPS in an ASP.NET Core application?

Mid
  • app.UseHttpsRedirection is middleware that automatically redirects HTTP requests to HTTPS. It is used to enforce secure communication over HTTPS.
  • To configure it, you add the middleware in the Configure method of the Startup class, typically after app.UseRouting and before other middleware. Additionally, you can customize redirection behavior using options in the Startup class.
Q29.

What is the purpose of the ModelState object in ASP.NET Core, and how is it used for validation?

Mid
  • The ModelState object in ASP.NET Core is used to store validation errors and values for model binding. It represents the state of model binding and validation for a specific request.
  • When validation fails, errors are added to the ModelState, and these errors can be checked in controllers to conditionally handle invalid input and return appropriate responses to the user.
Q30.

Explain the role of the IActionFilter and IAuthorizationFilter interfaces in ASP.NET Core.

Mid
  • IActionFilter and IAuthorizationFilter are filter interfaces that allow developers to customize the behavior of controllers. IActionFilter provides hooks before and after action execution, enabling tasks such as logging or modifying the response.
  • IAuthorizationFilter is used for custom authorization logic. Filters implementing these interfaces can be applied globally, at the controller level, or on specific actions to modify the request or response.
Q31.

Explain the role of the DbContext in Entity Framework Core. How does it relate to database interactions in an ASP.NET Core application?

Mid
  • The DbContext in Entity Framework Core is a crucial component that represents the session with the database.
  • It is responsible for tracking changes to entities, managing database connections, and facilitating the interaction between the application and the underlying database.
  • Developers use the DbContext to perform CRUD (Create, Read, Update, Delete) operations on the database through LINQ queries.
Q32.

How can you handle exceptions globally in an ASP.NET Core application?

Mid
  • Global exception handling in ASP.NET Core can be achieved by using the UseExceptionHandler middleware in the Startup class.
  • This middleware catches unhandled exceptions, logs them, and optionally redirects the user to an error page.
  • By configuring the ExceptionHandler middleware, you can provide a centralized way to handle exceptions across the entire application.
Q33.

Explain the role of the UseStaticFiles middleware in ASP.NET Core.

Mid
  • The UseStaticFiles middleware is used to serve static files (e.g., CSS, JavaScript, images) in an ASP.NET Core application. It is configured in the Startup class and should be placed before other middleware to ensure static files are processed first.
  • The middleware is configured to specify the directory containing the static files and the request path to map to that directory.
Q34.

What is the purpose of the ModelState.AddModelError method in ASP.NET Core?

Mid
  • ModelState.AddModelError is a method used to add a model-level error to the ModelState dictionary in ASP.NET Core. It is commonly used in controllers during form validation.
  • When a validation error occurs, this method is used to add an error message to the ModelState, which can then be checked in the view to display error messages to the user.
Q35.

Explain the purpose of the FromServices attribute in ASP.NET Core.

Mid
  • The FromServices attribute in ASP.NET Core is used to specify that a parameter in a controller action should be resolved from the dependency injection container. By default, parameters are bound from the request, but using FromServices allows the parameter to be injected as a service.
Q36.

Explain the purpose of the ITempDataDictionary in ASP.NET Core.

Mid
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Q37.

Explain the purpose of the [ApiController] attribute in ASP.NET Core controllers. How does it affect the behavior of a controller and its actions?

Mid
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Q38.

What is the purpose of the [Produces] attribute in ASP.NET Core controllers? How can it be used to specify the content types a controller action can produce?

Mid
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Q39.

Explain the differences between services.AddSingleton, services.AddScoped, and services.AddTransient in ASP.NET Core dependency injection. When would you use each?

Senior
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Q40.

What is the role of the UseSwagger and UseSwaggerUI methods in ASP.NET Core, and how can they be used to document and test APIs?

Senior
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Q41.

Explain the purpose of the IWebHostEnvironment interface in ASP.NET Core?

Senior
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Q42.

What is the purpose of the ITagHelper interface in ASP.NET Core, and how can it be used to extend HTML functionality in Razor views?

Senior
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Q43.

Explain the role of the app.UseHsts middleware in ASP.NET Core, and how can it enhance the security of a web application?

Senior
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.
Q44.

Explain the role of the app.UseForwardedHeaders middleware in ASP.NET Core.

Senior
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem.

About TechPrep

TechPrep has helped thousands of engineers land their dream jobs in Big Tech and beyond. Covering 60+ topics, including coding and DSA challenges, system design write-ups, and interactive quizzes, TechPrep saves you time, builds your confidence, and makes technical interviews a breeze.