Why ASP.NET Core
TrapWeb Forms never moved to Core.
Program.cs has two halves. Register services on builder.Services , call builder.Build(), then add middleware to app.next short-circuits the request.TrapWeb Forms never moved to Core.
ConfigureServices Configurebuilder.Services app.UseRouting() TipServices go in Configure or builder., middleware in Configure or on app.
TrapStartup still works. Microsoft advises against it.
IWebHostIHostWebApplicationTipKestrel can run alone or behind IIS, Nginx or Apache. A proxy can add HTTPS certificates and load balancing.
TrapIWebHost and WebHostBuilder are obsolete in .NET 10. Using them gives a compiler warning.
nextapp.Use(...)app.Run(...)app.Map(...)next. That short-circuits the pipeline.TipWebApplication implements IApplication, which builds the pipeline.
TrapA Run handler ends the pipeline, so nothing added after it is called.
TrapAuthorization placed before authentication sees every user as anonymous.
Asked in interviews
AskedWhy is the order of middleware important in ASP.NET Core?next, then handle the requestRequestDelegateInvokeAsync(ctx) app.UseMiddleware<T>() IMiddlewareTrapConvention-based middleware is created once for the app. Add scoped services as InvokeAsync parameters.
Asked in interviews
AskedHow do you create custom middleware in ASP.NET Core?wwwroot on .NET 9+app.MapStaticAssets() app.UseStaticFiles() TipMapStaticAssets compresses and fingerprints the files.
Trapwwwroot is the web root, and everything in it is public. Never put secrets there.
HttpContext.TipRazor Pages use page filters. Minimal APIs use endpoint filters.
UseExceptionHandler() AddProblemDetails() IExceptionHandler TipCreateBuilder turns on the Developer Exception Page in Development only.
TrapOnce the response has started, you can't change the status code.
Asked in interviews
AskedHow do you handle exceptions in ASP.NET Core?Two requests, each injecting the service three times. Singleton keeps one instance, scoped makes two and transient makes six.
AddSingleton<I, T>()AddScoped<I, T>()AddTransient<I, T>()IServiceScopeFactory TrapA singleton holding a scoped service is a captive dependency. Scope validation throws in Development.
AddKeyedSingleton<I, T>("big")[FromKeyedServices("big")] TipWithout keys, you get the last registration.
TrapA key with no registration fails only at run time, with an Invalid.
Asked in interviews
AskedWhat problem do keyed services solve in ASP.NET Core?Logging__LogLevel__Default TrapNever store passwords in appsettings.. It often ends up in source control.
config["Api:Key"]GetValue<int>(key, 30)GetConnectionString(name) Configure<T>(section)TrapGetSection never returns null, so a null check won't catch a missing section.
Asked in interviews
AskedHow do you use the IConfiguration interface?IOptions<T>Read once, the cheapestIOptionsSnapshot<T> Recompute per requestIOptionsMonitor<T> Always read current valuesTrapIOptions is scoped, so you can't inject it into a singleton.
ASPNETCORE_ENVIRONMENT IWebHostEnvironment IsDevelopment()IHostingEnvironment TrapWith no variable set, the app runs as Production.
dotnet user-secrets set "Api:Key" "123"TrapThe Secret Manager's file isn't encrypted. Use it for development only.
Asked in interviews
AskedHow do you manage sensitive data in an ASP.NET Core application?ILogger<T>LogInformation("Item {Id}", id)TipSet levels in the Logging section. The default is Information.
TrapDon't build the string yourself. Named placeholders let providers store the values as fields.
Asked in interviews
AskedHow is logging implemented in ASP.NET Core?{controller=Home}/{action=Index}/{id?} [HttpGet("{id}")] UseRouting picks it. UseEndpoints runs it.TipMiddleware between them can read endpoint metadata.
TrapA failed {id:int} constraint returns 404, but bad input should return 400.
AddControllers() MapControllers() CreatedAtAction(...) app.MapGet(path, handler)TipDerive from ControllerBase. [ApiController] requires attribute routing and returns 400 on bad input.
[FromQuery][FromBody]ValidationAttribute IValidatableObject TrapWithout [ApiController], the action runs on a bad model. Check Model.
Asp.Versioning.Mvc Asp.Versioning.Http Microsoft.AspNetCore.Mvc.Versioning /api/v1/products HeaderApiVersionReader TrapBy default every client must send a version. Set Assume to keep old clients working.
Asked in interviews
AskedHow do you implement API versioning in ASP.NET Core Web APIs?AddOpenApi()app.MapOpenApi() Swashbuckle.AspNetCore.SwaggerUi AddSwaggerGen()TrapKeep both in Development only, or you expose API details.
AddRateLimiter(...) app.UseRateLimiter() RequireRateLimiting(name) TrapPartition by user or API key. Partitioning on an IP address can itself open a denial of service risk.
Asked in interviews
AskedHow do you implement rate limiting in an ASP.NET Core Web API?IHttpContextAccessor TrapIt's recycled after the request and it isn't thread-safe. Copy the values you need before you start other work.
Asked in interviews
AskedWhat is HttpContext, and why shouldn't you use it outside its request?[Area("Billing")]OnGet()OnPost()[BindProperty]TipA Razor Page is a .cshtml file with @page plus a PageModel. Its URL comes from its path.
@Model.Name@model@injectasp-action="Index" asp-for="Name"TrapRazor HTML-encodes every string it outputs. Html.Raw skips that, so user input can inject markup.
<partial name="_Cart" />Component.InvokeAsync("Cart") TrapView components never handle HTTP requests and don't use model binding.
[ValidateAntiForgeryToken] return View(model);RedirectToAction(name) TipThe final redirect is Post/Redirect/Get. It stops a refresh from posting twice.
TrapAPIs that use a bearer token in a header, not a cookie, aren't exposed to CSRF.
InteractiveServer InteractiveWebAssembly InteractiveAutoTipThe fourth mode, static server rendering, sends plain HTML.
Asked in interviews
AskedWhat is Blazor and how does it integrate with ASP.NET Core?AddLocalization() UseRequestLocalization() IStringLocalizer<T> TipCulture formats dates and numbers. UI culture picks the translated strings.
Asked in interviews
AskedHow do you implement globalization and localization in ASP.NET Core?AddAuthentication(...) .AddJwtBearer(...) TipAnonymous users get a challenge, a login redirect for cookie-protected pages or a 401. Users without permission get a forbid, a 403 with JWT.
TrapConfiguring authentication restricts nothing. Authorization does that.
Asked in interviews
AskedHow do you implement authentication in ASP.NET Core?[Authorize][AllowAnonymous] Roles = "Admin"Policy = "AtLeast21"AddPolicy(name, ...)AuthorizationHandler<T> IAuthorizationService FallbackPolicyTrapWith a fallback policy, static files placed after authorization need a sign-in too.
AddCors(...)WithOrigins(url) app.UseCors(name) [EnableCors]UseHttpsRedirection() UseHsts()TipAdd a Content Security Policy, and show detailed errors only in Development.
TrapCORS isn't a protection, because it relaxes the same-origin policy. Never combine AllowAnyOrigin with Allow.
AddDbContext<AppDb>(...) DbContext is already a Repository and Unit of Work.TipMake one repository per aggregate root, never one per table.
TrapA DbContext is scoped and isn't thread-safe. Never hold one in a singleton.
dotnet ef migrations add Namedotnet ef database updatedotnet ef migrations bundledotnet ef migrations scriptTrapA migration may drop a column you meant to rename. Review the code before you apply it.
Asked in interviews
AskedHow do you manage database migrations with EF Core?AddStackExchangeRedisCache() IDistributedCache HybridCacheAddSession()app.UseSession() TipThe session cookie holds only the ID. Data expires after 20 idle minutes by default.
TrapAdd stays on one server, so a farm needs sticky sessions or a shared cache.
TipMessages use JSON by default, or MessagePack for smaller binary messages.
Asked in interviews
AskedWhat is SignalR?greet.protoAddGrpc()MapGrpcService<T>() TrapBrowser apps must use gRPC-Web, which drops client and bidirectional streaming.
Asked in interviews
AskedWhat is gRPC and how can it be used in ASP.NET Core?BackgroundService AddHostedService<T>() stoppingToken to every awaited call.TrapAfter a crash, StopAsync may never run, so work held in memory is lost. Durable jobs need a persistent queue.
Asked in interviews
AskedHow do you implement background tasks in ASP.NET Core?dotnet new webapidotnet rundotnet publishdotnet publish --self-containedAddHealthChecks() MapHealthChecks(path) TipA process manager restarts the app after a crash or a reboot.
TrapBehind a proxy, the app may not see the original scheme or client IP. Add Forwarded Headers middleware.
TypedResults.ServerSentEvents Tip.NET 10 is LTS, from November 2025.
Nothing matches. Try a shorter word, or clear the search.
With Pro, you can:
Already have Pro? Sign in