What is ASP.NET Core, and how is it different from
Short answer: SP.NET MVC 5? ASP.NET Core is a cross-platform, open-source framework for building modern web pplications, APIs, and microservices. It’s a complete rewrite of the old ASP.NET framework, designed to be lightweight, modular, and cloud-ready. Key Differences: Feature ASP.NET MVC 5 ASP.NET Core Platform Windows only Cross-platform (Windows, macOS,… Linux)……… Hosting IIS only Kestrel, IIS, Nginx, Apache, self-hosting…
Explain a bit more
Configuration web.config (XML) appsettings.json (JSON-based) Dependency Injection Third-party libraries Built-in DI container Modularity Monolithic Modular via NuGet packages Example: In ASP.NET MVC 5, you’d deploy only to IIS on Windows. {
Example code
public void ConfigureServices(IServiceCollection services)
{ services.AddControllers(); }
public void Configure(IApplicationBuilder app)
{ pp.UseRouting(); pp.UseEndpoints(endpoints => endpoints.MapControllers());
}
} 🧭 6. Explain the purpose of Program.cs in .NET 6+. In .NET 6+, Startup.cs and Program.cs merged into one minimal host configuration file. It sets up the web host, configuration, logging, and middleware pipeline. Example: var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); var app = builder.Build(); pp.MapControllers(); pp.Run(); It’s simpler, faster, and easier to read. Minimal APIs are a lightweight way to build small HTTP APIs without controllers or ttributes. Perfect for microservices. Example: var app = WebApplication.Create(args);
{ [HttpGet("{id}")] public IActionResult Get(int id) => Ok($"Product {id}");
} 🧩 11. What is Endpoint Routing? Endpoint routing separates route matching from execution. It lets middleware (like authentication) know which endpoint will be executed before it runs. Example: pp.UseRouting(); pp.UseAuthorization(); pp.UseEndpoints(endpoints => endpoints.MapControllers()); 🔄 12. Explain the role of middleware in ASP.NET Core. Middleware are components that handle requests and responses in a pipeline. Each can: Process requests Call the next middleware Or short-circuit the pipeline Example: logging middleware that runs before all others: pp.Use(async (context, next) => { Console.WriteLine("Request: " + context.Request.Path); wait next(); }); 🕒 13. What is the order of middleware execution? Middleware execute in the order they’re added in Program.cs. Response flows in reverse order back up the chain. Tip: Authentication must come before Authorization. UseRouting must come before UseEndpoints. 🧩 14. How to create custom middleware? Example: public class RequestLoggingMiddleware
{
private readonly RequestDelegate _next;
public RequestLoggingMiddleware(RequestDelegate next) => _next = next; public async Task Invoke(HttpContext context)
{ Console.WriteLine($"Request for: {context.Request.Path}"); wait _next(context); }
} Register it: pp.UseMiddleware<RequestLoggingMiddleware>(); 🧱 15. What is the difference between middleware and filters? Feature Middleware Filter Scope Entire app Controller/action level Runs on Every request MVC actions only Example Authentication, logging Validation, exception filters ⚒ 16. Explain the IApplicationBuilder interface. IApplicationBuilder builds the middleware pipeline. You use it in Startup.Configure() or Program.cs to add middleware via Use, Run, nd Map. 🔀 17. Difference between Use, Run, and Map in middleware. Metho Description Example Use Adds middleware that can call the next component. pp.UseMiddleware<Logging>(); Run Terminates the pipeline — no next middleware. pp.Run(async c => await c.Response.WriteAsync("End")); Map Branches pipeline based on request path. pp.Map("/admin", a => .Run(...)); 🏗 18. What are Hosting Models in ASP.NET Core (In-process vs Out-of-process)? Model Description Performance In-process App runs inside IIS worker process (w3wp.exe). Faster (single process) Out-of-proces IIS acts as reverse proxy to Kestrel. Slight overhead Example: For Windows servers, in-process gives best performance. For cross-platform Docker, use out-of-process. 🌍 19. Explain Web Host vs Generic Host. Host Type Used For Example Web Host Web apps (ASP.NET Core ≤ 2.2) WebHost.CreateDefaultBui lder() Generic Host ny app: web, worker, console (≥ 3.0) Host.CreateDefaultBuilde r() Generic Host unifies background tasks, APIs, and services in one model. ⚙ 20. How does configuration binding work in SP.NET Core? ASP.NET Core can automatically bind configuration from: appsettings.json Environment variables Command-line arguments Example: // appsettings.json { "AppSettings": { "SiteName": "MyShop", "Version": "1.0" }
} // POCO public class AppSettings
{
public string SiteName { get; set; }
public string Version { get; set; }
} // Program.cs builder.Services.Configure<AppSettings>( builder.Configuration.GetSection("AppSettings")); You can inject IOptions<AppSettings> anywhere. MVC Architecture & Controllers
Real-world example (ShopNest)
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png