Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: Async filters implement IAsyncActionFilter and support await, improving scalability. Example code Async filters implement IAsyncActionFilter and support await, improving scalability. Real-world example (Sho…
Short answer: 🏦 Fintech API – Global Exception Filter Ensures consistent error envelopes across microservices. 🛠 Microservices – Audit Logging Tracks when sensitive controller actions are executed. 👮 Role-based Author…
Short answer: custom page or handler. if (env.IsDevelopment()) pp.UseDeveloperExceptionPage(); else pp.UseExceptionHandler("/Error"); Or inline: pp.UseExceptionHandler(errorApp => { errorApp.Run(async contex…
Short answer: (UseExceptionHandler, UseDeveloperExceptionPage) UseDeveloperExceptionPage() shows detailed errors (development only). UseExceptionHandler("/Error") handles errors in production with a custom page…
Short answer: Yes. They form a pipeline based on their defined order. Real-world example (ShopNest) A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every contr…
Short answer: Filters execute per controller action → use sparingly. Avoid heavy DB calls. Avoid creating new HttpClients or DbContexts inside filters. Prefer asynchronous filters. Real-world example (ShopNest) A ShopNes…
Short answer: pp.UseHttpsRedirection(); dd early in the pipeline, before auth or routing. Explain a bit more You can configure HTTPS ports in launchSettings.json or ppsettings.json. pp.UseHttpsRedirection(); dd early in…
Short answer: Redirects HTTP requests to HTTPS. app.UseHttpsRedirection(); Add early in the pipeline, before auth or routing. You can configure HTTPS ports in launchSettings.json or appsettings.json. Real-world example (…
Short answer: Use: ActionExecutingContext mocks ActionExecutedContext mocks DefaultHttpContext var httpContext = new DefaultHttpContext(); var context = new ActionExecutingContext(...); Focus tests on: Expected results S…
Short answer: app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "MyFiles")), RequestPath = "/Files", OnPrepareResponse = ctx => {…
Short answer: When your logic depends on controller/action context, such as reading route values or action arguments. Real-world example (ShopNest) ShopNest pipeline order matters: exception handling → HTTPS → auth → aut…
Short answer: Mistake Fix Doing authentication inside action filters Use authorization filters Performing heavy logic Move to middleware Not registering filters as services Use DI for maintainability Returning inconsiste…
Short answer: pp.Run(async ctx => { wait ctx.Response.WriteAsync("This ends the pipeline"); }); pp.Run(async ctx => { wait ctx.Response.WriteAsync("This ends the pipeline"); }); pp.Run(async ctx…
Short answer: middleware Type Description Terminal Ends the pipeline. Doesn’t call next(). E.g., app.Run() Non-Termi nal Calls next() and allows other middlewares to run after it. E.g., app.Use() Terminal middleware: app…
Short answer: Yes—action filters have full access to ActionArguments. Real-world example (ShopNest) ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threadi…
Short answer: app.UseAuthentication(); // Validates user identity app.UseAuthorization(); // Applies policies/roles Order matters: must be after routing but before endpoints. app.UseRouting(); app.UseAuthentication(); ap…
Short answer: Filters provide clean, reusable cross-cutting logic for MVC pipelines. Use the right filter type for the right stage. Prefer middleware when you don’t need controller context. Exception filters are best for…
Short answer: Exception filters only catch exceptions from MVC actions; middleware catches exceptions from the entire pipeline. Real-world example (ShopNest) ShopNest pipeline order matters: exception handling → HTTPS →…
Short answer: pp.UseCors("MyPolicy"); Must be placed before routing/endpoints. pp.UseCors("MyPolicy"); Must be placed before routing/endpoints. pp.UseCors("MyPolicy"); Must be placed before…
Short answer: builder.Services.AddCors(options => { options.AddPolicy("MyPolicy", policy => { policy.WithOrigins(" .AllowAnyHeader() .AllowAnyMethod(); }); }); app.UseCors("MyPolicy"); Must…
Short answer: Use: services.AddControllers(options => { options.Filters.Add(typeof(AuditLogFilter)); }); Advanced Level Example code Use: services.AddControllers(options => { options.Filters.Add(typeof(AuditLogFilt…
Short answer: wait _next(context); sw.Stop(); Console.WriteLine($"Request took {sw.ElapsedMilliseconds} ms"); } } Register: pp.UseMiddleware<TimingMiddleware>(); Dependency Injection (DI) wait _next(conte…
Short answer: execution time) Example custom middleware to measure time: public class TimingMiddleware Example code { private readonly RequestDelegate _next; public TimingMiddleware(RequestDelegate next) => _next = ne…
Short answer: Filters specifically built for Minimal APIs (introduced in ASP.NET Core 7). Real-world example (ShopNest) A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same…
Short answer: ✅ Capabilities: Constructor injection Lifetime management (Transient, Scoped, Singleton) Supports IEnumerable<T>, IServiceProvider, and open generics ⚠ Limitations: No support for named registrations…
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Async filters implement IAsyncActionFilter and support await, improving scalability.
Async filters implement IAsyncActionFilter and support await, improving scalability.
ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: 🏦 Fintech API – Global Exception Filter Ensures consistent error envelopes across microservices. 🛠 Microservices – Audit Logging Tracks when sensitive controller actions are executed. 👮 Role-based Authorization Custom authorization filter validating role claims dynamically. 🚀 Performance Profiling Times how long each controller method takes. public class ProfilingFilter : IActionFilter
{
private Stopwatch _watch;
public void OnActionExecuting(ActionExecutingContext context)
{
_watch = Stopwatch.StartNew();
}
public void OnActionExecuted(ActionExecutedContext context)
{ _watch.Stop(); Console.WriteLine($"Action took {_watch.ElapsedMilliseconds} ms"); }
}
A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: custom page or handler. if (env.IsDevelopment()) pp.UseDeveloperExceptionPage(); else pp.UseExceptionHandler("/Error"); Or inline: pp.UseExceptionHandler(errorApp => { errorApp.Run(async context => { context.Response.StatusCode = 500; wait context.Response.WriteAsync("An error occurred"); }); }); custom page or handler.…
if… (env.IsDevelopment()) pp.UseDeveloperExceptionPage(); else pp.UseExceptionHandler("/Error"); Or inline: pp.UseExceptionHandler(errorApp => { errorApp.Run(async context => { context.Response.StatusCode = 500; wait context.Response.WriteAsync("An error occurred"); }); }); custom page or handler. Example: if (env.IsDevelopment()) pp.UseDeveloperExceptionPage(); else pp.UseExceptionHandler("/Error"); Or inline: pp.UseExceptionHandler(errorApp => { errorApp.Run(async context => { context.Response.StatusCode = 500; wait context.Response.WriteAsync("An error occurred"); }); }); custom page or handler.… Example: if (env.IsDevelopment()) pp.UseDeveloperExceptionPage(); else pp.UseExceptionHandler("/Error"); Or inline: pp.UseExceptionHandler(errorApp => { errorApp.Run(async context => { context.Response.StatusCode = 500; wait context.Response.WriteAsync("An error occurred"); }); });
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: (UseExceptionHandler, UseDeveloperExceptionPage) UseDeveloperExceptionPage() shows detailed errors (development only). UseExceptionHandler("/Error") handles errors in production with a custom page or handler. Example: if (env.IsDevelopment()) app.UseDeveloperExceptionPage(); else app.UseExceptionHandler("/Error"); Or inline: app.UseExceptionHandler(errorApp => { errorApp.Run(async context => {
context.Response.StatusCode = 500;
await context.Response.WriteAsync("An error occurred"); }); });
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Yes. They form a pipeline based on their defined order.
A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Filters execute per controller action → use sparingly. Avoid heavy DB calls. Avoid creating new HttpClients or DbContexts inside filters. Prefer asynchronous filters.
A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: pp.UseHttpsRedirection(); dd early in the pipeline, before auth or routing.
You can configure HTTPS ports in launchSettings.json or ppsettings.json. pp.UseHttpsRedirection(); dd early in the pipeline, before auth or routing. You can configure HTTPS ports in launchSettings.json or ppsettings.json. pp.UseHttpsRedirection(); dd early in the pipeline, before auth or routing. You can configure HTTPS ports in launchSettings.json or ppsettings.json. pp.UseHttpsRedirection(); dd early in the pipeline, before auth or routing. You can configure HTTPS ports in launchSettings.json or ppsettings.json.
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Redirects HTTP requests to HTTPS. app.UseHttpsRedirection(); Add early in the pipeline, before auth or routing. You can configure HTTPS ports in launchSettings.json or appsettings.json.
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Use: ActionExecutingContext mocks ActionExecutedContext mocks DefaultHttpContext var httpContext = new DefaultHttpContext(); var context = new ActionExecutingContext(...); Focus tests on: Expected results Short-circuiting behavior Context manipulation
Use: ActionExecutingContext mocks ActionExecutedContext mocks DefaultHttpContext var httpContext = new DefaultHttpContext();
var context = new ActionExecutingContext(...); Focus tests on: Expected results Short-circuiting behavior Context manipulation
A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "MyFiles")), RequestPath = "/Files", OnPrepareResponse = ctx => { ctx.Context.Response.Headers.Append("Cache-Control", "public,max-age=600"); } }); For directory browsing: app.UseDirectoryBrowser(new DirectoryBrowserOptions { FileProvider = new PhysicalFileProvider("path"), RequestPath = "/browse" });
ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: When your logic depends on controller/action context, such as reading route values or action arguments.
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Mistake Fix Doing authentication inside action filters Use authorization filters Performing heavy logic Move to middleware Not registering filters as services Use DI for maintainability Returning inconsistent error messages Handle errors via global exception filter
A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: pp.Run(async ctx => { wait ctx.Response.WriteAsync("This ends the pipeline"); }); pp.Run(async ctx => { wait ctx.Response.WriteAsync("This ends the pipeline"); }); pp.Run(async ctx => { wait ctx.Response.WriteAsync("This ends the pipeline"); }); pp.Run(async ctx => { wait ctx.Response.WriteAsync("This ends the pipeline"); });
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: middleware Type Description Terminal Ends the pipeline. Doesn’t call next(). E.g., app.Run() Non-Termi nal Calls next() and allows other middlewares to run after it. E.g., app.Use() Terminal middleware: app.Run(async ctx => { await ctx.Response.WriteAsync("This ends the pipeline"); });
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Yes—action filters have full access to ActionArguments.
ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: app.UseAuthentication(); // Validates user identity app.UseAuthorization(); // Applies policies/roles Order matters: must be after routing but before endpoints. app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(...);
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Filters provide clean, reusable cross-cutting logic for MVC pipelines. Use the right filter type for the right stage. Prefer middleware when you don’t need controller context. Exception filters are best for consistent error handling. Use DI for scalable, clean, testable filter implementations. Filters shine in enterprise applications: auditing, authorization, and response shaping.
A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Exception filters only catch exceptions from MVC actions; middleware catches exceptions from the entire pipeline.
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: pp.UseCors("MyPolicy"); Must be placed before routing/endpoints. pp.UseCors("MyPolicy"); Must be placed before routing/endpoints. pp.UseCors("MyPolicy"); Must be placed before routing/endpoints. pp.UseCors("MyPolicy"); Must be placed before routing/endpoints.
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: builder.Services.AddCors(options => { options.AddPolicy("MyPolicy", policy => { policy.WithOrigins(" .AllowAnyHeader() .AllowAnyMethod(); }); }); app.UseCors("MyPolicy"); Must be placed before routing/endpoints.
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Use: services.AddControllers(options => { options.Filters.Add(typeof(AuditLogFilter)); }); Advanced Level
Use: services.AddControllers(options => { options.Filters.Add(typeof(AuditLogFilter)); }); Advanced Level
A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: wait _next(context); sw.Stop(); Console.WriteLine($"Request took {sw.ElapsedMilliseconds} ms"); } } Register: pp.UseMiddleware<TimingMiddleware>(); Dependency Injection (DI) wait _next(context); sw.Stop(); Console.WriteLine($"Request took {sw.ElapsedMilliseconds} ms"); } } Register: pp.UseMiddleware<TimingMiddleware>(); Dependency… Injection (DI) wait… _next(context); sw.Stop(); Console.WriteLine($"Request took…
{sw.ElapsedMilliseconds} ms"); } } Register: pp.UseMiddleware<TimingMiddleware>(); Dependency Injection (DI) wait _next(context); sw.Stop(); Console.WriteLine($"Request took {sw.ElapsedMilliseconds} ms"); } } Register: pp.UseMiddleware<TimingMiddleware>(); Dependency… Injection (DI)
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: execution time) Example custom middleware to measure time: public class TimingMiddleware
{
private readonly RequestDelegate _next;
public TimingMiddleware(RequestDelegate next) => _next = next; public async Task InvokeAsync(HttpContext context)
{
var sw = Stopwatch.StartNew();
await _next(context); sw.Stop(); Console.WriteLine($"Request took {sw.ElapsedMilliseconds} ms"); }
} Register: app.UseMiddleware<TimingMiddleware>(); Dependency Injection (DI)
ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Filters specifically built for Minimal APIs (introduced in ASP.NET Core 7).
A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: ✅ Capabilities: Constructor injection Lifetime management (Transient, Scoped, Singleton) Supports IEnumerable<T>, IServiceProvider, and open generics ⚠ Limitations: No support for named registrations Limited property injection Basic feature set compared to Autofac or other 3rd-party containers
ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.
Install Toolliyo like an app Free
Home-screen access to tutorials, coding practice & career tools — no app store needed.
On iPhone/iPad: tap Share then Add to Home Screen.