📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š .NET Interview Questions

1325 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.

Request Handling

Model binding, validation, MVC filters and endpoint filters, custom model binders, formatters and content negotiation, ProblemDetails, status code pages and exception handling middleware.

  1. How does model binding work in ASP.NET Core? Explain the binding sources ([FromRoute], [FromQuery], [FromBody], [FromHeader], [FromForm], [FromServices], [AsParameters]) and the rules each framework uses to infer the source when you don't specify one, in controllers versus Minimal APIs.

    Model binding in ASP.NET Core: the binding source attributes, how controllers with [ApiController] and Minimal APIs infer sources for simple types, complex types, services and special types, the one-body rule, [AsParameters] parameter objects, and what happens when binding fails.

    Junior Theory Request Handling Β· πŸ”— 2 follow-ups
  2. How do you validate requests in ASP.NET Core? Cover DataAnnotations, the automatic 400 from [ApiController], FluentValidation, and the built-in Minimal API validation added in .NET 10. Where do business rules belong compared with input validation?

    Request validation in ASP.NET Core .NET 10: DataAnnotations and IValidatableObject, ModelState and the [ApiController] automatic ValidationProblemDetails 400, FluentValidation (manual or via filters), AddValidation() for Minimal APIs, and the split between input validation and domain/business rules.

    Intermediate Theory Request Handling Β· πŸ”— 2 follow-ups
  3. What are MVC filters in ASP.NET Core? Explain the authorisation, resource, action, exception and result filters, the order they run in, how scope (global, controller, action) and the Order property affect them, and when you would use a filter instead of middleware.

    MVC filters in ASP.NET Core: the five filter stages and their order relative to model binding and result execution, sync vs async filter interfaces, scope ordering and IOrderedFilter, short-circuiting, DI in filters (ServiceFilter, TypeFilter, IFilterFactory), and choosing filters versus middleware versus endpoint filters.

    Mid-Level Theory Request Handling Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  4. What are endpoint filters in Minimal APIs? Write a reusable filter with IEndpointFilter, apply it to a route group, and explain how filter ordering works and what a filter can see and change.

    Coding question on Minimal API endpoint filters: IEndpointFilter and inline AddEndpointFilter, EndpointFilterInvocationContext and argument access, short-circuiting with a result, applying filters to route groups, onion ordering of group and endpoint filters, filter factories, and when to use endpoint filters versus middleware or .NET 10 built-in validation.

    Intermediate Coding Request Handling Β· πŸ”— 2 follow-ups
  5. How do you bind your own types from a request in ASP.NET Core? Show TryParse and BindAsync for Minimal APIs and a custom model binder for controllers, using a strongly typed ID and a comma-separated list as examples, and explain when each is appropriate.

    Coding question on custom binding: IParsable/TryParse for simple types such as strongly typed IDs, static BindAsync for types built from several request parts, custom IModelBinder and IModelBinderProvider for MVC (comma-separated lists), TypeConverter, JSON converters for body properties, and how each affects OpenAPI and validation.

    Mid-Level Coding Request Handling Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  6. How do formatters and content negotiation work in ASP.NET Core? Explain the Accept and Content-Type headers, configuring System.Text.Json options, adding the XML formatter, when you get a 406 or 415, and how Minimal APIs differ from controllers here.

    Input and output formatters and content negotiation: Accept-driven output formatter selection in MVC, ReturnHttpNotAcceptable and 406, Content-Type and 415, JsonOptions for MVC versus Microsoft.AspNetCore.Http.Json.JsonOptions for Minimal APIs, System.Text.Json source generation, adding XML formatters, and Minimal APIs being JSON-only.

    Intermediate Theory Request Handling Β· πŸ”— 2 follow-ups
  7. What is ProblemDetails (RFC 9457), and how do you return consistent error responses in ASP.NET Core? Explain AddProblemDetails, IProblemDetailsService, status code pages, how UseExceptionHandler uses them, and how you add a trace id and your own error codes.

    ProblemDetails in ASP.NET Core .NET 10: the RFC 9457 shape (type, title, status, detail, instance, extensions), ValidationProblemDetails, AddProblemDetails and CustomizeProblemDetails, IProblemDetailsService and IProblemDetailsWriter, UseStatusCodePages for empty error responses, UseExceptionHandler and IExceptionHandler integration, adding traceId and stable error codes, and not leaking internals.

    Mid-Level Theory Request Handling Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  8. A client says your API ignores their data: the request object arrives as null or with default values, or they get a 415, and nothing in the logs explains it. Possible causes include JSON casing, enums sent as strings, a missing [FromBody], the wrong Content-Type, and type mismatches. How do you diagnose and fix it?

    Debugging silent model binding failures in ASP.NET Core: 415 from a wrong or missing Content-Type, null bodies from JSON errors or empty bodies, default values from casing or naming mismatches, enums as strings without JsonStringEnumConverter, number/string and date format mismatches, missing [FromBody] or [ApiController], and the tools to see the real error (ModelState, ThrowOnBadRequest, Debug logging, request logging).

    Mid-Level Debugging Request Handling Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  9. Your API must accept file uploads of up to 2 GB. How do you handle large uploads and streaming request bodies in ASP.NET Core? Compare IFormFile buffering with streaming through MultipartReader or the raw body, explain the size limits at each layer, and how you keep memory use flat.

    Large file uploads in ASP.NET Core: IFormFile buffering to memory and temp disk (FormOptions.MemoryBufferThreshold, MultipartBodyLengthLimit), streaming with MultipartReader or Request.Body/BodyReader, Kestrel MaxRequestBodySize and per-endpoint overrides, MinRequestBodyDataRate, proxy and IIS limits, direct-to-Blob uploads with SAS, validation, malware scanning and anti-forgery.

    Senior Theory Request Handling Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  10. Code review: a controller action wraps everything in try/catch and returns 200 with { success: false, error: ex.Message }, binds an EF Core entity directly from the request body and saves it, and validates fields by hand with if statements. What problems do you find, ranked by severity, and how would you rewrite it?

    Code review of a typical problematic controller: catch-all returning 200 with exception messages (information disclosure, broken HTTP semantics, swallowed errors), over-posting by binding EF entities, mass assignment of sensitive fields, hand-rolled validation, sync-over-async and missing cancellation, and a rewrite with request DTOs, validation, ProblemDetails, proper status codes and global exception handling.

    Senior CodeReview Request Handling Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me