Monday, November 10, 2025

Top 20 ASP.NET Core Interview Questions and Answers (2025 edition)

1. What is ASP.NET Core?

Answer:
ASP.NET Core is a cross-platform, high-performance, open-source framework developed by Microsoft for building modern, cloud-based, and internet-connected applications. It’s a redesign of ASP.NET and runs on .NET Core or .NET (5/6/7+).


2. What are the key differences between ASP.NET and ASP.NET Core?

Answer:

Feature ASP.NET ASP.NET Core
Platform Windows only Cross-platform
Hosting Model IIS IIS, Kestrel, Self-host
Performance Moderate High
Dependency Injection Limited Built-in
Configuration web.config appsettings.json

3. What is Middleware in ASP.NET Core?

Answer:
Middleware is software that’s assembled into the application pipeline to handle requests and responses. It can process requests before they reach the endpoint and after the response leaves it.

Example:

app.UseMiddleware<CustomMiddleware>();

4. What is Kestrel?

Answer:
Kestrel is a cross-platform web server for ASP.NET Core. It's the default web server and is designed for high performance.


5. Explain the Startup.cs file.

Answer:
Startup.cs is the entry point for configuring services and the app’s request pipeline.

  • ConfigureServices(IServiceCollection services): Registers services with DI.

  • Configure(IApplicationBuilder app, ...): Sets up middleware.


6. What is Dependency Injection (DI)?

Answer:
DI is a design pattern used to inject dependencies rather than creating them manually. ASP.NET Core has built-in DI support via the IServiceCollection.


7. How do you configure routing in ASP.NET Core?

Answer:
Routing is configured using endpoints:

app.UseRouting();

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");
});

8. What is the difference between AddTransient, AddScoped, and AddSingleton?

Answer:

  • Transient: New instance every time.

  • Scoped: One instance per request.

  • Singleton: One instance for the app lifetime.


9. How is configuration handled in ASP.NET Core?

Answer:
ASP.NET Core uses configuration providers and reads from:

  • appsettings.json

  • Environment variables

  • Command-line arguments

Injected using:

public class MyClass(IConfiguration config) { }

10. What are Tag Helpers?

Answer:
Tag Helpers enable server-side code to participate in creating and rendering HTML elements in Razor views.

Example:

<a asp-controller="Home" asp-action="About">About</a>

11. How is logging handled in ASP.NET Core?

Answer:
ASP.NET Core uses built-in ILogger<T> and supports logging to:

  • Console

  • Debug

  • EventSource

  • External providers like Serilog, NLog


12. What is the Program.cs file in .NET 6/7/8 projects?

Answer:
Program.cs uses a minimal hosting model combining Startup and Program into one file.

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", () => "Hello World!");
app.Run();

13. How do you implement authentication and authorization?

Answer:

  • Authentication: AddAuthentication() and middleware

  • Authorization: [Authorize] attributes and policies

services.AddAuthentication(...);
services.AddAuthorization(...);

14. What is Razor Pages?

Answer:
Razor Pages is a page-focused web development model, simpler than MVC. Each .cshtml page has its own model (PageModel class).


15. How do you handle exceptions globally?

Answer:
Use UseExceptionHandler() or middleware.

app.UseExceptionHandler("/Home/Error");

Or custom middleware for API:

app.UseMiddleware<ErrorHandlingMiddleware>();

16. How can you create and consume Web APIs?

Answer:
Use [ApiController], and RESTful routing:

[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
    [HttpGet] public IActionResult GetAll() => Ok(...);
}

17. What is Model Binding in ASP.NET Core?

Answer:
Model binding maps incoming data (route, query string, form) to parameters or model objects.


18. What are Filters in ASP.NET Core?

Answer:
Filters are used to execute code before or after specific stages in the request pipeline:

  • Authorization

  • Action

  • Result

  • Exception


19. How is session management done?

Answer:
Enable session services and middleware:

services.AddSession();
app.UseSession();

Use:

HttpContext.Session.SetString("key", "value");

20. How do you implement caching?

Answer:

  • In-memory caching:

services.AddMemoryCache();
  • Use:

_cache.Set("key", data, TimeSpan.FromMinutes(5));

- Best of luck for interview

Prasad :)😇

Saturday, February 22, 2025

TOP 20 SQL interview questions for 2025

 






TOP 20 SQL interview questions for 2025

Hey Candidates here are the Top 20 SQL, that will help you crack the SQL interview

1. What is SQL?

SQL (Structured Query Language) is a standard language for accessing and manipulating databases. It is used for querying, updating, and managing data stored in a relational database.

2. What are the differences between SQL and MySQL?

  • SQL is a standard language for accessing and manipulating databases, while MySQL is a relational database management system (RDBMS) that uses SQL as its standard database language.
  • SQL is a query language, and MySQL is software for managing databases.
  • SQL commands are used in various database systems, whereas MySQL is a specific implementation of an RDBMS.
3. What are DDL and DML commands? Give examples.
  • DDL (Data Definition Language) commands are used to define the database structure. Examples include CREATE, ALTER, and DROP.
  • DML (Data Manipulation Language) commands are used for managing data within the database. Examples include SELECT, INSERT, UPDATE, and DELETE.
4. Write a query to retrieve all records from a table.

SELECT * FROM table_name;
5. How do you Join 2 tables
Tables can be joined using various types of joins, such as INNER JOIN, LEFT JOIN, RIGHT JOIN, 
and FULL JOIN. Here's an example using INNER JOIN:
SELECT *
FROM table1
INNER JOIN table2 ON table1.common_column = table2.common_column;
6. What is the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN?
  • INNER JOIN returns records that have matching values in both tables.
  • LEFT JOIN returns all records from the left table and matched records from the right table. If no match, NULL values are returned for columns of the right table.
  • RIGHT JOIN returns all records from the right table and matched records from the left table. If no match, NULL values are returned for columns of the left table.
  • FULL JOIN returns all records when there is a match in either left or right table. If there is no match, the result is NULL from the side where there is no match.
7. Explain the concept of normalization. 
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity. It involves dividing large tables into smaller tables and defining relationships between them. Common forms of normalization are 1NF, 2NF, 3NF, and BCNF.

8. What is indexing? How does it improve query performance? 
Indexing involves creating a data structure (index) that improves the speed of data retrieval operations on a database table. Indexes provide a quick lookup for matching rows in a table based on indexed columns, thus reducing the time required for data access.

9. Write a query to find the second highest salary from an Employee table.
SELECT MAX(salary) AS SecondHighestSalary
FROM Employee
WHERE salary < (SELECT MAX(salary) FROM Employee);
10. What is a primary key and a foreign key?
A primary key is a column (or a combination of columns) that uniquely identifies each row in a table.
A foreign key is a column (or a combination of columns) that establishes a relationship between two 
tables by referencing the primary key of another table.
11. Explain the difference between DELETE and TRUNCATE.
DELETE is a DML command used to delete specific rows from a table based on a condition.
 It can be rolled back.
TRUNCATE is a DDL command used to remove all rows from a table, resetting it to an empty state. 
It cannot be rolled back and is faster than DELETE.
12. What is a subquery? Provide an example.
A subquery is a query within another query. It is used to return data that will be used in the main query 
as a condition.
SELECT employee_name FROM employees WHERE department_id = (SELECT department_id FROM departments
WHERE department_name = 'Sales');

13. How do you handle transactions in SQL?

Transactions are handled using the following commands:

  • BEGIN TRANSACTION: Starts a transaction.

  • COMMIT: Saves all changes made during the transaction.

  • ROLLBACK: Reverts all changes made during the transaction.

14. What are stored procedures and functions?
  • A stored procedure is a set of SQL statements that can be executed as a single unit. It can perform

actions such as data modification and return multiple values.
  • A function is a set of SQL statements that perform a specific task and return a single value.

Functions are typically used for calculations and data manipulation.

15. Explain the concept of ACID properties in databases.

ACID stands for Atomicity, Consistency, Isolation, and Durability. These properties ensure reliable

processing of database transactions:

  • Atomicity: Ensures that all operations within a transaction are completed; if not, the transaction

is aborted.
  • Consistency: Ensures that the database remains in a consistent state before and after a transaction.

  • Isolation: Ensures that transactions are isolated from each other, preventing concurrent

transactions from interfering with each other.
  • Durability: Ensures that once a transaction is committed, it remains permanent, even in the case

of a system failure.

16. What is the difference between a VIEW and a TABLE?

  • A TABLE is a database object that stores data in rows and columns.

  • A VIEW is a virtual table based on the result set of a SQL query. It does not store data

physically but provides a way to simplify complex queries and enhance security by restricting access
to specific data.

17. How do you optimize SQL queries?

  • Use indexes to speed up data retrieval.

  • Avoid using SELECT * and only select required columns.

  • Use JOINs instead of subqueries when possible.

  • Write efficient WHERE clauses to filter data early.

  • Analyze query execution plans to identify performance bottlenecks.

18. What is the difference between DISTINCT and GROUP BY?

  • DISTINCT is used to remove duplicate rows from a result set.

  • GROUP BY is used to group rows that have the same values in specified columns and perform

aggregate functions (e.g., COUNT, SUM) on them.

19. Explain the concept of database normalization.
Normalization is the process of organizing data in a database to reduce redundancy and improve
data integrity. It involves dividing large tables into smaller tables and defining relationships between
them. Common forms of normalization are 1NF, 2NF, 3NF, and BCNF.

20. What is the purpose of the ORDER BY clause? The ORDER BY clause is used to sort the result set of a query by one or more columns.
It can be used to sort data in ascending (ASC) or descending (DESC) order.

BEST LUCK !!!