Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: ASP.NET Core configuration is flexible, layered, and environment-aware. Explain a bit more It reads settings from multiple sources (JSON files, environment variables, command-line rgs, etc.) and merges them…
Short answer: builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationS cheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateA…
Short answer: var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); ap…
Short answer: options.UseLazyLoadingProxies().UseSqlServer(...); options.UseLazyLoadingProxies().UseSqlServer(...); options.UseLazyLoadingProxies().UseSqlServer(...); options.UseLazyLoadingProxies().UseSqlServer(...); Re…
Short answer: Middleware vs Filters vs Handlers Concept When It Runs Scope Example Middleware Before/after request Global Logging, authentication Filters Around controller/action Controller/action Authorization, validati…
Short answer: dotnet publish -c Release -o C:\inetpub\wwwroot\MyApp Real-world example (ShopNest) ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely. Say this i…
Short answer: builder.Services.AddStackExchangeRedisCache(options => { options.Configuration = "localhost:6379"; }); builder.Services.AddStackExchangeRedisCache(options => { options.Configuration = "…
Short answer: Environment variables are great for overriding settings at deployment time (especially in Docker or Azure). Example: set ASPNETCORE_ENVIRONMENT=Production set ConnectionStrings__Default="Server=mydb;Da…
Short answer: [Authorize] [ApiController] [Route("api/[controller]")] public class OrdersController : ControllerBase { [HttpGet] public IActionResult GetOrders() => Ok("Secured Orders"); } [Authori…
Short answer: public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : Ident…
Short answer: Use compiled queries for frequently executed queries.? is a common interview topic in ASP.NET Core MVC. Give a clear definition, then one concrete example. Real-world example (ShopNest) ShopNest admin scree…
Short answer: public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Cat…
Short answer: SignalR vs WebSockets Feature WebSockets SignalR Protocol Low-level TCP-based High-level abstraction Transpor Only WebSockets Fallbacks: WebSockets → SSE → Long Polling Usage Real-time messages Real-time hu…
Short answer: How to Host in Azure App Service? Answer: Azure App Service provides PaaS hosting for ASP.NET Core apps. Steps: Publish the app via Visual Studio, CLI, or GitHub Actions. dotnet publish -c Release Create Ap…
Short answer: pp.MapHealthChecks("/health"); pp.MapHealthChecks("/health"); pp.MapHealthChecks("/health"); pp.MapHealthChecks("/health"); pp.MapHealthChecks("/health"); p…
Short answer: Role-based authorization restricts access based on user roles. ssign a role: wait _userManager.AddToRoleAsync(user, "Admin"); Use in controllers: [Authorize(Roles = "Admin")] public IAct…
Short answer: pp.UseExceptionHandler("/Home/Error"); or public class GlobalExceptionFilter : IExceptionFilter { public void OnException(ExceptionContext context) { context.Result = new ViewResult { ViewName = &…
Short answer: builder.Services.AddHealthChecks(); app.MapHealthChecks("/health"); builder.Services.AddHealthChecks(); app.MapHealthChecks("/health"); builder.Services.AddHealthChecks(); app.MapHealthC…
Short answer: Application Insights provides monitoring, telemetry, and tracing. Setup: builder.Services.AddApplicationInsightsTelemetry(builder.Configurati on["APPINSIGHTS_INSTRUMENTATIONKEY"]); Features: Track…
Short answer: TestContainers spins up real Docker containers (SQL Server, Redis) for integration testing, simulating production. Explain a bit more using Testcontainers.MsSql; var sqlContainer = new MsSqlBuilder() .WithP…
Short answer: Partial views are used to render reusable page sections (like headers, sidebars). public IActionResult ProductList() var products = _service.GetAll(); return PartialView("_ProductListPartial", pro…
Short answer: Using SignalR for Real-Time Communication // Hub public class ChatHub : Hub { public async Task SendMessage(string user, string message) => await Clients.All.SendAsync("ReceiveMessage", user, m…
Short answer: zure App Service PaaS Easy scaling, HTTPS CI/CD GitHub Actions / Azure DevOps Automated build/test/deploy Logging ILogger, Serilog, NLog Use structured logging Monitoring Application Insights, Prometheus Tr…
Short answer: Docker allows running ASP.NET Core apps in containers, portable across environments. Dockerfile Example: # Build stage FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /app COPY *.csproj ./ RUN dotnet…
Short answer: public class LogActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext context) { Console.WriteLine($"Action: {context.ActionDescriptor.DisplayName}")…
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: ASP.NET Core configuration is flexible, layered, and environment-aware.
It reads settings from multiple sources (JSON files, environment variables, command-line rgs, etc.) and merges them into a single configuration object (IConfiguration).
In Program.cs: var builder = WebApplication.CreateBuilder(args); // Access configuration var appName = builder.Configuration["AppSettings:Name"]; SP.NET Core automatically loads:
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationS cheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = " ValidAudience = " IssuerSigningKey = new… SymmetricSecurityKey(……… Encoding.UTF8.GetBytes("super-secret-key-123")) }; });…
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationS cheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true, ValidateLifetime = true, ValidateIssuerSigningKey = true, ValidIssuer = " ValidAudience = " IssuerSigningKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes("super-secret-key-123")) }; }); builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationS cheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateAudience = true,…
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build();…
app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization();
var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization(); var app = builder.Build(); app.UseAuthentication(); app.UseAuthorization();
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: options.UseLazyLoadingProxies().UseSqlServer(...); options.UseLazyLoadingProxies().UseSqlServer(...); options.UseLazyLoadingProxies().UseSqlServer(...); options.UseLazyLoadingProxies().UseSqlServer(...);
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: Middleware vs Filters vs Handlers Concept When It Runs Scope Example Middleware Before/after request Global Logging, authentication Filters Around controller/action Controller/action Authorization, validation Handlers Authentication/Authorization Global or endpoint JWT handler, Cookie auth 1⃣
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: dotnet publish -c Release -o C:\inetpub\wwwroot\MyApp
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: builder.Services.AddStackExchangeRedisCache(options => { options.Configuration = "localhost:6379"; }); builder.Services.AddStackExchangeRedisCache(options => { options.Configuration = "localhost:6379"; }); builder.Services.AddStackExchangeRedisCache(options => { options.Configuration = "localhost:6379"; });… builder.Services.AddStackExchangeRedisCache(options => { options.Configuration = "localhost:6379"; });
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: Environment variables are great for overriding settings at deployment time (especially in Docker or Azure). Example: set ASPNETCORE_ENVIRONMENT=Production set ConnectionStrings__Default="Server=mydb;Database=App;User=sa;Passwor d=123" Notice the double underscores __ for nested keys. {
private readonly IWebHostEnvironment _env;
public HomeController(IWebHostEnvironment env)
{
_env = env;
}
public IActionResult Index()
{
if (_env.IsDevelopment())
return Content("Running in Development mode");
return Content($"Environment: {_env.EnvironmentName}");
}
} You can also access it in Program.cs: if (builder.Environment.IsProduction())
{ // Configure production services } 🧾 8. How to use different appsettings.json files? ASP.NET Core supports environment-specific JSON files. Example structure: ppsettings.json ppsettings.Development.json ppsettings.Staging.json ppsettings.Production.json Program.cs: builder.Configuration .AddJsonFile("appsettings.json") .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.jso n", optional: true); t runtime, only the file matching the current environment will override base settings. Example: ppsettings.json { "AppName": "MyApp", "LogLevel": "Information" } ppsettings.Production.json { "LogLevel": "Error" } Result in Production → LogLevel = Error. 🔄 9. How to reload configuration dynamically? You can make JSON configuration files auto-reload when changed. Example: builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); If you update appsettings.json, the new values are reflected automatically in your app without restarting. You can subscribe to changes using IOptionsMonitor (see below). 📦 10. How to bind configuration to POCO classes? You can map sections of your configuration directly to C# classes (POCOs). Example: ppsettings.json { "AppSettings": { "SiteName": "TechStore", "PageSize": 20, "EnableCache": true }
} Create a POCO: public class AppSettings
{
public string SiteName { get; set; }
public int PageSize { get; set; }
public bool EnableCache { get; set; }
} Bind configuration: builder.Services.Configure<AppSettings>( builder.Configuration.GetSection("AppSettings")); Inject it into a controller: public class HomeController : Controller
{
private readonly AppSettings _settings;
public HomeController(IOptions<AppSettings> options)
{
_settings = options.Value;
}
public IActionResult Index()
{
return Content($"Welcome to {_settings.SiteName}!");
}
} You can also use IOptionsSnapshot for per-request reload or IOptionsMonitor for live updates. Web APIs & REST
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: [Authorize] [ApiController] [Route("api/[controller]")] public class OrdersController : ControllerBase { [HttpGet] public IActionResult GetOrders() => Ok("Secured Orders"); } [Authorize] [ApiController] [Route("api/[controller]")] public class OrdersController : ControllerBase { [HttpGet] public IActionResult GetOrders() =>… Ok("Secured Orders"); }… [Authorize] [ApiController] [Route("api/[controller]")] public…
class OrdersController : ControllerBase { [HttpGet] public IActionResult GetOrders() => Ok("Secured Orders"); } [Authorize] [ApiController] [Route("api/[controller]")] public class OrdersController : ControllerBase { [HttpGet] public IActionResult GetOrders() =>… Ok("Secured Orders"); }
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get;…
set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } }
public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } } public class ApplicationUser : IdentityUser { public string FullName { get; set; } }
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: Use compiled queries for frequently executed queries.? is a common interview topic in ASP.NET Core MVC. Give a clear definition, then one concrete example.
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; }
public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; } public virtual Category Category { get; set; }
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: SignalR vs WebSockets Feature WebSockets SignalR Protocol Low-level TCP-based High-level abstraction Transpor Only WebSockets Fallbacks: WebSockets → SSE → Long Polling Usage Real-time messages Real-time hubs with automatic reconnection, grouping, scaling ✅ Use SignalR for apps needing broadcast, connection management, and fallbacks.
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: How to Host in Azure App Service? Answer: Azure App Service provides PaaS hosting for ASP.NET Core apps. Steps: Publish the app via Visual Studio, CLI, or GitHub Actions. dotnet publish -c Release Create App Service in Azure portal. Deploy using FTP, Git, or CI/CD pipelines. App Service automatically configures Kestrel + reverse proxy. ✅ Supports scaling, HTTPS, and monitoring out-of-the-box.
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: pp.MapHealthChecks("/health"); pp.MapHealthChecks("/health"); pp.MapHealthChecks("/health"); pp.MapHealthChecks("/health"); pp.MapHealthChecks("/health"); pp.MapHealthChecks("/health"); pp.MapHealthChecks("/health"); pp.MapHealthChecks("/health");
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: Role-based authorization restricts access based on user roles. ssign a role: wait _userManager.AddToRoleAsync(user, "Admin"); Use in controllers: [Authorize(Roles = "Admin")] public IActionResult Dashboard() => View(); You can also combine roles: [Authorize(Roles = "Admin,Manager")] 🧭 7. {
public int Age { get; }
public MinimumAgeRequirement(int age) => Age = age;
}
public class MinimumAgeHandler : uthorizationHandler<MinimumAgeRequirement> { protected override Task HandleRequirementAsync( uthorizationHandlerContext context, MinimumAgeRequirement requirement) {
var birthDateClaim = context.User.FindFirst(c => c.Type == "BirthDate"); if (birthDateClaim != null)
{
var birthDate = DateTime.Parse(birthDateClaim.Value);
if (birthDate.AddYears(requirement.Age) <= DateTime.Today) context.Succeed(requirement); }
return Task.CompletedTask;
}
} Register it: builder.Services.AddAuthorization(options => { options.AddPolicy("AdultOnly", policy => policy.Requirements.Add(new MinimumAgeRequirement(18))); }); builder.Services.AddSingleton<IAuthorizationHandler, MinimumAgeHandler>(); Use it: [Authorize(Policy = "AdultOnly")] public IActionResult BuyAlcohol() => Ok("Access granted"); 🍪 9. What is cookie authentication in ASP.NET Core? Cookie authentication stores user information in an encrypted cookie on the browser. When the user revisits, the cookie is used to identify them. Configure: builder.Services.AddAuthentication(CookieAuthenticationDefaults.Auth enticationScheme) .AddCookie(options => {
options.LoginPath = "/Account/Login";
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: pp.UseExceptionHandler("/Home/Error"); or public class GlobalExceptionFilter : IExceptionFilter { public void OnException(ExceptionContext context) { context.Result = new ViewResult { ViewName = "Error" }; } } 🧩 19.
pp.UseExceptionHandler("/Home/Error"); or public class GlobalExceptionFilter : IExceptionFilter { public void OnException(ExceptionContext context) { context.Result = new ViewResult { ViewName = "Error" }; } } 🧩 19. {
public void OnException(ExceptionContext context)
{
context.Result = new ViewResult { ViewName = "Error" };
}
} 🧩 19. How to return partial views? Partial views are used to render reusable page sections (like headers, sidebars). Example: public IActionResult ProductList()
{
var products = _service.GetAll();
return PartialView("_ProductListPartial", products);
} In Razor: @Html.Partial("_ProductListPartial", Model.Products) 🧾 20. Explain Razor Pages vs MVC. Feature Razor Pages MVC Structure Page-based (.cshtml + .cshtml.cs) Controller + View Best For Simple or CRUD pages Complex or large web apps URL /Products/Edit → /Pages/Products/Edit.cshtml /Products/Edit → ProductController.Edit() Code Location In the same file (PageModel) Separate Controller class Example: Razor Pages are like simplified MVC without controllers — great for admin dashboards or forms. Dependency Injection (DI)
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: builder.Services.AddHealthChecks(); app.MapHealthChecks("/health"); builder.Services.AddHealthChecks(); app.MapHealthChecks("/health"); builder.Services.AddHealthChecks(); app.MapHealthChecks("/health"); builder.Services.AddHealthChecks(); app.MapHealthChecks("/health");
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: Application Insights provides monitoring, telemetry, and tracing. Setup: builder.Services.AddApplicationInsightsTelemetry(builder.Configurati on["APPINSIGHTS_INSTRUMENTATIONKEY"]); Features: Track requests, exceptions, and dependencies Live metrics and dashboards Custom events and telemetry 9⃣ How to Monitor Performance and Uptime?
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: TestContainers spins up real Docker containers (SQL Server, Redis) for integration testing, simulating production.
using Testcontainers.MsSql; var sqlContainer = new MsSqlBuilder() .WithPassword("yourStrong(!)Password") .Build(); wait sqlContainer.StartAsync(); var options = new DbContextOptionsBuilder<AppDbContext>() .UseSqlServer(sqlContainer.GetConnectionString()) .Options; // Use context in tests ✅ Benefits: Real database behavior CI/CD friendly Close to production setup Deployment & Hosting How to Deploy an ASP.NET Core App to IIS? TestContainers spins up real Docker containers (SQL Server, Redis) for integration testing, simulating production.
using Testcontainers.MsSql; var sqlContainer = new MsSqlBuilder() .WithPassword("yourStrong(!)Password") .Build(); wait sqlContainer.StartAsync(); var options = new DbContextOptionsBuilder<AppDbContext>() .UseSqlServer(sqlContainer.GetConnectionString()) .Options; // Use context in tests ✅ Benefits: Real database behavior CI/CD friendly Close to production setup Deployment & Hosting How to Deploy an ASP.NET Core App to IIS? TestContainers spins up real Docker containers (SQL Server, Redis) for integration testing, simulating production. Example: using Testcontainers.MsSql; var sqlContainer = new MsSqlBuilder() .WithPassword("yourStrong(!)Password") .Build(); wait sqlContainer.StartAsync(); var options = new DbContextOptionsBuilder<AppDbContext>() .UseSqlServer(sqlContainer.GetConnectionString()) .Options; // Use context in tests ✅ Benefits: Real database behavior CI/CD friendly Close to production setup Deployment & Hosting How to Deploy an ASP.NET Core App to IIS? IIS (Internet Information Services) can host ASP.NET Core apps via the ASP.NET Core Module, which forwards requests to Kestrel. Steps: TestContainers spins up real Docker containers (SQL Server, Redis) for integration testing, simulating production. Example: using Testcontainers.MsSql; var sqlContainer = new MsSqlBuilder() .WithPassword("yourStrong(!)Password") .Build(); wait sqlContainer.StartAsync(); var options = new DbContextOptionsBuilder<AppDbContext>() .UseSqlServer(sqlContainer.GetConnectionString()) .Options; // Use context in tests ✅ Benefits: Real database behavior CI/CD friendly Close to production setup Deployment & Hosting How to Deploy an ASP.NET Core App to IIS? IIS (Internet Information Services) can host ASP.NET Core apps via the ASP.NET Core Module, which forwards requests to Kestrel. Steps:
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: Partial views are used to render reusable page sections (like headers, sidebars). public IActionResult ProductList() var products = _service.GetAll(); return PartialView("_ProductListPartial", products); In Razor: Follow : @Html.Partial("_ProductListPartial", Model.Products) 🧾 20. Partial views are used to render reusable page sections (like headers, sidebars).
public IActionResult ProductList() var products = _service.GetAll(); return PartialView("_ProductListPartial", products); In Razor: Follow : @Html.Partial("_ProductListPartial", Model.Products) 🧾 20. Partial views are used to render reusable page sections (like headers, sidebars). Example: public IActionResult ProductList() var products = _service.GetAll(); return PartialView("_ProductListPartial", products); In Razor: Follow : @Html.Partial("_ProductListPartial", Model.Products) 🧾 20. Explain Razor Pages vs MVC. Feature Razor Pages MVC Structure Page-based (.cshtml + .cshtml.cs) Controller + View Best For Simple or CRUD pages Complex or large web apps URL /Products/Edit → /Pages/Products/Edit.cshtml /Products/Edit → ProductController.Edit() Code Location In the same file (PageModel) Separate Controller class Example: Razor Pages are like simplified MVC without controllers — great for admin dashboards or forms. Dependency Injection (DI) Partial views are used to render reusable page sections (like headers, sidebars). Example: public IActionResult ProductList() var products = _service.GetAll(); return PartialView("_ProductListPartial", products); In Razor: Follow : @Html.Partial("_ProductListPartial", Model.Products) 🧾 20. Explain Razor Pages vs MVC. Feature Razor Pages MVC Structure Page-based (.cshtml + .cshtml.cs) Controller + View Best For Simple or CRUD pages Complex or large web apps URL /Products/Edit → /Pages/Products/Edit.cshtml /Products/Edit → ProductController.Edit() Code Location In the same file (PageModel) Separate Controller class Example: Razor Pages are like simplified MVC without controllers — great for admin dashboards or forms. Dependency Injection (DI)
ShopNest’s product edit form posts to an MVC action. Model binding fills a ProductEditVm; the action validates and redisplay the view on errors.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: Using SignalR for Real-Time Communication // Hub public class ChatHub : Hub { public async Task SendMessage(string user, string message) => await Clients.All.SendAsync("ReceiveMessage", user, message); } // Client (JavaScript) const connection = new signalR.HubConnectionBuilder() .withUrl("/chathub") .build(); connection.on("ReceiveMessage", (user, message) => { console.log(`${user}: ${message}`); }); await…
connection.start(); await connection.invoke("SendMessage", "Alice", "Hello!");
Using SignalR for Real-Time Communication // Hub public class ChatHub : Hub
{
public async Task SendMessage(string user, string message) =>
await Clients.All.SendAsync("ReceiveMessage", user, message); } // Client (JavaScript) const connection = new signalR.HubConnectionBuilder() .withUrl("/chathub") .build(); connection.on("ReceiveMessage", (user, message) => { console.log(`${user}: ${message}`); }); await connection.start();
await connection.invoke("SendMessage", "Alice", "Hello!");
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: zure App Service PaaS Easy scaling, HTTPS CI/CD GitHub Actions / Azure DevOps Automated build/test/deploy Logging ILogger, Serilog, NLog Use structured logging Monitoring Application Insights, Prometheus Track metrics, uptime Health Checks ASP.NET Core HealthChecks Expose /health endpoints This gives a complete production-ready workflow from… deployment… to…… monitoring.
zure App Service PaaS Easy scaling, HTTPS CI/CD GitHub Actions / Azure DevOps Automated build/test/deploy Logging ILogger, Serilog, NLog Use structured logging Monitoring Application Insights, Prometheus Track metrics, uptime Health Checks ASP.NET Core HealthChecks Expose /health endpoints This gives a complete production-ready workflow from deployment to… monitoring. dvanced & Modern Topics Middleware Pipeline in Depth ASP.NET Core handles HTTP requests through a middleware pipeline, which is a sequence of components where each can: Inspect or modify the request Call the next middleware Short-circuit the pipeline Pipeline Flow: Request -> Middleware1 -> Middleware2 ->…… {
public async Task SendMessage(string user, string message) => wait Clients.All.SendAsync("ReceiveMessage", user, message); } // Client (JavaScript) const connection = new signalR.HubConnectionBuilder() .withUrl("/chathub") .build(); connection.on("ReceiveMessage", (user, message) => { console.log(`${user}: ${message}`); }); wait connection.start(); wait connection.invoke("SendMessage", "Alice", "Hello!"); 5⃣ Background Services (IHostedService) For long-running tasks or scheduled jobs Implement IHostedService or extend BackgroundService public class TimedWorker : BackgroundService
{ protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { Console.WriteLine("Running background task"); wait Task.Delay(10000, stoppingToken); }
}
} builder.Services.AddHostedService<TimedWorker>(); ✅ Good for periodic jobs, email processing, queue consumers. 6⃣ Hangfire or Quartz.NET for Background Jobs Hangfire Example: pp.UseHangfireDashboard(); RecurringJob.AddOrUpdate(() => Console.WriteLine("Recurring job"), Cron.Daily); Quartz.NET: Supports cron-like scheduling and clustered execution. 7⃣ Health Checking in ASP.NET Core builder.Services.AddHealthChecks() .AddSqlServer(connectionString) .AddCheck<CustomHealthCheck>("CustomCheck"); pp.MapHealthChecks("/health"); Custom Health Check Example: public class CustomHealthCheck : IHealthCheck
{
public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken token) => Task.FromResult(HealthCheckResult.Healthy("Everything OK")); } 8⃣ Rate Limiting Middleware in .NET 8 builder.Services.AddRateLimiter(options => { options.GlobalLimiter = PartitionedRateLimiter.Create<HttpContext, string>(httpContext => RateLimitPartition.GetFixedWindowLimiter(httpContext.Connection.Remo teIpAddress?.ToString()!, _ => new FixedWindowRateLimiterOptions { PermitLimit = 10, Window = TimeSpan.FromMinutes(1), QueueLimit = 2 })); }); pp.UseRateLimiter(); ✅ Helps protect APIs from abuse or DoS attacks. 9⃣ DataAnnotations for Validation public class Product
{ [Required] public string Name { get; set; } [Range(1, 100)] public decimal Price { get; set; }
} Works with model binding Automatic client & server-side validation with Razor or API endpoints 🔟 Global Exception Logging pp.UseExceptionHandler(errorApp => { errorApp.Run(async context => {
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: Docker allows running ASP.NET Core apps in containers, portable across environments. Dockerfile Example: # Build stage FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build WORKDIR /app COPY *.csproj ./ RUN dotnet restore COPY .
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.
ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC
Short answer: public class LogActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext context) { Console.WriteLine($"Action: {context.ActionDescriptor.DisplayName}"); } } Use it: [LogActionFilter] public IActionResult Index() => View(); 📤 15.
How do you pass data from controller to view?
public class LogActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext context) { Console.WriteLine($"Action: {context.ActionDescriptor.DisplayName}"); } } Use it: [LogActionFilter] public IActionResult Index() => View(); 📤 15. How do you pass data from controller to view? public class LogActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext context) { Console.WriteLine($"Action: {context.ActionDescriptor.DisplayName}"); } } Use it: [LogActionFilter] public IActionResult Index() => View(); 📤 15. How do you pass data from controller to view? public class LogActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext context) { Console.WriteLine($"Action: {context.ActionDescriptor.DisplayName}"); } } Use it: [LogActionFilter] public IActionResult Index() => View(); 📤 15. How do you pass data from controller to view? public class LogActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext context) { Console.WriteLine($"Action: {context.ActionDescriptor.DisplayName}"); } } Use it: [LogActionFilter] public IActionResult Index() => View(); 📤 15. How do you pass data from controller to view? You can use: public class LogActionFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext context) { Console.WriteLine($"Action: {context.ActionDescriptor.DisplayName}"); }
} Use it: [LogActionFilter] public IActionResult Index() => View(); 📤 15. How do you pass data from controller to view? You can use:
ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.