التخطي إلى المحتوى الرئيسي

Top 50 .NET Core MVC Interview Question and Answer in 2025

 Top 50 .NET Core MVC Interview Question and Answer in 2025 

ASP.NET Core MVC Questions (1-20)

  1. What is ASP.NET Core MVC?
    ASP.NET Core MVC is a cross-platform, open-source framework for building web applications using the Model-View-Controller pattern, offering high performance and flexibility.
  2. How is ASP.NET Core different from ASP.NET MVC?
    ASP.NET Core is cross-platform, modular, and lightweight, while ASP.NET MVC runs only on Windows and relies on the .NET Framework.
  3. What is the role of the Program.cs file in ASP.NET Core?
    It serves as the entry point, configuring the application’s services and middleware pipeline using the Host Builder.
  4. What is dependency injection in ASP.NET Core?
    DI is a design pattern built into ASP.NET Core to manage object creation and lifecycle, promoting loose coupling by injecting dependencies via constructors or properties.
  5. What are middleware components in ASP.NET Core?
    Middleware are components in the request pipeline that handle requests and responses, e.g., authentication, routing, or logging.
  6. What is the purpose of the Startup class?
    In earlier ASP.NET Core versions, the Startup class configured services (ConfigureServices) and the request pipeline (Configure). Now, this is often done in Program.cs.
  7. What is Razor syntax?
    Razor is a markup syntax that allows embedding C# code in HTML to create dynamic views efficiently.
  8. What is the difference between ViewBag and ViewData?
    ViewBag is a dynamic wrapper around ViewData (a dictionary), allowing property-style access, but both transfer data from controller to view. ViewBag is less type-safe.
  9. What is Tag Helpers in ASP.NET Core?
    Tag Helpers are server-side components that simplify HTML generation and enhance readability, e.g., <form asp-action="Submit">.
  10. How do you enable routing in ASP.NET Core MVC?
    Routing is enabled via middleware (app.UseRouting()) and configured with endpoints (app.UseEndpoints()) in Program.cs.
  11. What is the purpose of Areas in MVC?
    Areas organize large applications into separate modules (e.g., Admin, User) with their own controllers, views, and models.
  12. What is Model Binding?
    Model Binding maps HTTP request data (e.g., form fields, query strings) to action method parameters or model properties.
  13. How do you handle validation in ASP.NET Core MVC?
    Use Data Annotations (e.g., [Required]) on model properties and check ModelState.IsValid in the controller.
  14. What is the difference between TempData and Session?
    TempData is short-lived (persists until read), used for redirects, while Session persists across requests and requires explicit configuration.
  15. What is the purpose of IActionResult?
    IActionResult is a return type for action methods, allowing flexible responses like View(), Json(), or Redirect().
  16. How do you implement custom filters in MVC?
    Create a class inheriting from ActionFilterAttribute and override methods like OnActionExecuting or OnActionExecuted.
  17. What is the role of the _Layout.cshtml file?
    It defines a common template for views, including headers, footers, and navigation, reducing code duplication.
  18. How do you secure an ASP.NET Core MVC app?
    Use authentication (e.g., Identity), authorization (e.g., [Authorize]), HTTPS, and middleware like UseAuthentication().
  19. What is the Razor Pages alternative to MVC?
    Razor Pages is a page-based model in ASP.NET Core that combines controller and view logic into a single file (e.g., .cshtml).
  20. What is the significance of appsettings.json?
    It stores configuration settings (e.g., connection strings) in a JSON format, accessible via the IConfiguration interface.

ASP.NET Core Web API Questions (21-35)

  1. What is ASP.NET Core Web API?
    It’s a framework for building RESTful APIs to handle HTTP requests and return data (e.g., JSON) for client applications.
  2. How does Web API differ from MVC?
    Web API returns data (e.g., JSON, XML) for APIs, while MVC typically returns views (HTML) for web pages.
  3. What is the purpose of [ApiController] attribute?
    It enables API-specific features like automatic model validation and problem details for errors.
  4. What are HTTP methods supported in Web API?
    GET (retrieve), POST (create), PUT (update), DELETE (remove), PATCH (partial update), etc.
  5. How do you handle versioning in Web API?
    Use URL versioning (e.g., /api/v1/), query string (?version=1), or headers with attributes like [ApiVersion("1.0")].
  6. What is Swagger in Web API?
    Swagger (via Swashbuckle) generates interactive API documentation and a UI for testing endpoints.
  7. How do you enable CORS in Web API?
    Add CORS policy in Program.cs with builder.Services.AddCors() and app.UseCors().
  8. What is the role of IActionResult in Web API?
    It allows returning HTTP responses like Ok(), NotFound(), or BadRequest() with appropriate status codes.
  9. How do you handle exceptions globally in Web API?
    Use middleware like app.UseExceptionHandler() or custom exception filters to catch and format errors.
  10. What is content negotiation in Web API?
    It determines the response format (e.g., JSON, XML) based on the Accept header sent by the client.
  11. How do you implement authentication in Web API?
    Use JWT (JSON Web Tokens), OAuth, or ASP.NET Core Identity with middleware like UseAuthentication().
  12. What is the purpose of [FromBody] attribute?
    It binds request body data (e.g., JSON) to a parameter in an action method.
  13. How do you rate-limit a Web API?
    Use the AspNetCoreRateLimit package or custom middleware to restrict request frequency.
  14. What is Minimal API in ASP.NET Core?
    A lightweight way to create APIs without controllers, using endpoints like app.MapGet("/data", () => "Hello").
  15. How do you unit test a Web API?
    Use frameworks like xUnit or NUnit, mock dependencies with Moq, and test endpoints with TestServer or HttpClient.

C# Questions (36-50)

  1. What are the new features in C# 12?
    Primary constructors, collection expressions, and default lambda parameters were introduced in C# 12 (released late 2023).
  2. What is the difference between async and await?
    async marks a method as asynchronous, while await pauses execution until the awaited task completes.
  3. What are nullable reference types?
    Introduced in C# 8, they allow marking reference types as nullable (e.g., string?) to avoid null reference exceptions.
  4. What is the difference between IEnumerable and IQueryable?
    IEnumerable executes in memory, while IQueryable builds queries for deferred execution, often with databases.
  5. What is a record type in C#?
    Introduced in C# 9, records are immutable data classes with built-in equality and value-based comparison.
  6. What is the purpose of using statement?
    It ensures proper disposal of resources (e.g., files, database connections) implementing IDisposable.
  7. What is the difference between struct and class?
    Structs are value types (stack-allocated), while classes are reference types (heap-allocated).
  8. What are extension methods?
    Static methods in static classes that extend existing types without modifying them, e.g., LINQ methods.
  9. What is pattern matching in C#?
    A feature to test and extract data from objects, enhanced in C# 9 with is and switch expressions.
  10. What is the purpose of var keyword?
    It enables implicit typing, letting the compiler infer the type at compile time.
  11. What is a delegate in C#?
    A type-safe function pointer that allows methods to be passed as parameters, e.g., Action or Func.
  12. What is the difference between Task and ValueTask?
    Task represents an asynchronous operation, while ValueTask is a lightweight alternative to avoid allocations in sync cases.
  13. What are attributes in C#?
    Metadata tags (e.g., [Obsolete]) applied to code elements, used for reflection or behavior modification.
  14. How does garbage collection work in C#?
    The GC automatically reclaims memory from unreachable objects in the managed heap, using generations (0, 1, 2).
  15. What is the difference between ref and out parameters?
    ref requires initialization before passing and allows two-way data flow; out requires assignment in the method and is for output only


تعليقات

المشاركات الشائعة من هذه المدونة

Uncontrolled form input in React-JS

  Uncontrolled form input in React-JS? If we want to take input from users without any separate event handling then we can uncontrolled the data binding technique. The uncontrolled input is similar to the traditional HTML form inputs. The DOM itself handles the form data. Here, the HTML elements maintain their own state that will be updated when the input value changes. To write an uncontrolled component, you need to use a ref to get form values from the DOM. In other words, there is no need to write an event handler for every state update. You can use a ref to access the input field value of the form from the DOM. Example of Uncontrolled Form Input:- import React from "react" ; export class Info extends React . Component {     constructor ( props )     {         super ( props );         this . fun = this . fun . bind ( this ); //event method binding         this . input = React . createRef ();...

JSP Page design using Internal CSS

  JSP is used to design the user interface of an application, CSS is used to provide set of properties. Jsp provide proper page template to create user interface of dynamic web application. We can write CSS using three different ways 1)  inline CSS:-   we will write CSS tag under HTML elements <div style="width:200px; height:100px; background-color:green;"></div> 2)  Internal CSS:-  we will write CSS under <style> block. <style type="text/css"> #abc { width:200px;  height:100px;  background-color:green; } </style> <div id="abc"></div> 3) External CSS:-  we will write CSS to create a separate file and link it into HTML Web pages. create a separate file and named it style.css #abc { width:200px;  height:100px;  background-color:green; } go into Jsp page and link style.css <link href="style.css"  type="text/css" rel="stylesheet"   /> <div id="abc"> </div> Exam...

JDBC using JSP and Servlet

JDBC means Java Database Connectivity ,It is intermediates from Application to database. JDBC has different type of divers and provides to communicate from database server. JDBC contain four different type of approach to communicate with Database Type 1:- JDBC-ODBC Driver Type2:- JDBC Vendor specific Type3 :- JDBC Network Specific Type4:- JDBC Client-Server based Driver  or JAVA thin driver:- Mostly we prefer Type 4 type of Driver to communicate with database server. Step for JDBC:- 1  Create Database using MYSQL ,ORACLE ,MS-SQL or any other database 2   Create Table using database server 3   Create Form according to database table 4  Submit Form and get form data into servlet 5  write JDBC Code:-     5.1)   import package    import java.sql.*     5.2)  Add JDBC Driver according to database ide tools     5.3)  call driver in program         ...