Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: For large uploads, use IFormFile, Stream, or read from Request.Body for streaming. For downloads, return FileStreamResult. Enable buffering or streaming to avoid memory overload. Example code For large uplo…
Short answer: pp.UseExceptionHandler(config => { config.Run(async context => { // Log and return problem details }); }); Or use ProblemDetails for structured error responses. Explain a bit more pp.UseExceptionHandl…
Short answer: Use UseExceptionHandler middleware or custom ExceptionMiddleware. You can also create a global error handler: app.UseExceptionHandler(config => { config.Run(async context => { // Log and return proble…
Short answer: Use proper status codes: 200 OK (success) 201 Created (on POST) 204 No Content (on DELETE) 400 Bad Request 401 Unauthorized / 403 Forbidden 404 Not Found 500 Internal Server Error return Ok(result); Example…
Short answer: ActionResult<T>: Combines a return value and response code. public ActionResult<Product> Get(int id) { ... } IActionResult: More flexible, returns different result types explicitly. Prefer Actio…
Short answer: ASP.NET Core supports full async/await pattern for IO-bound tasks. [HttpGet] public async Task<ActionResult<Product>> GetAsync(int id) { Example code var product = await _repo.GetAsync(id); retu…
Short answer: NotFound() : Ok(product); ✅ Improves scalability and performance. NotFound() : Ok(product); ✅ Improves scalability and performance. NotFound() : Ok(product); ✅ Improves scalability and performance. NotFound…
Short answer: Enable CORS (Cross-Origin Resource Sharing) to allow client apps from different domains: services.AddCors(options => { options.AddPolicy("AllowFrontend", builder => builder.WithOrigins("…
Short answer: ASP.NET Core doesn't include rate limiting out of the box (pre-.NET 8). Use libraries like: AspNetCoreRateLimit YARP, Azure API Management .NET 8 introduced built-in RateLimiterMiddleware. Real-world exampl…
Short answer: pp.UseSwagger(); pp.UseSwaggerUI(); Supports: Auto-generated OpenAPI docs Try it out interface Versioning support pp.UseSwagger(); pp.UseSwaggerUI(); Supports: Auto-generated OpenAPI docs Try it out interfa…
Short answer: Use Swashbuckle.AspNetCore or NSwag for generating Swagger docs. services.AddSwaggerGen(); app.UseSwagger(); app.UseSwaggerUI(); Supports: Auto-generated OpenAPI docs Try it out interface Versioning support…
Short answer: Unit testing: Mock services/repositories using Moq or FakeItEasy. Integration testing: Use WebApplicationFactory<T> + TestServer + HttpClient. var client = _factory.CreateClient(); Example code var re…
Short answer: Use JWT Bearer Tokens for stateless auth: services.AddAuthentication(JwtBearerDefaults.AuthenticationSch eme) .AddJwtBearer(options => { ... }); Secure endpoints with: [Authorize(Roles = "Admin"…
Short answer: HTTPS: Enforced via UseHttpsRedirection() CORS: Limit origins using policies Anti-forgery: Usually not needed for APIs unless using cookies (use ValidateAntiForgeryToken) Use authentication + authorization…
Short answer: DTOs decouple internal models from API contracts. Use AutoMapper for mapping: CreateMap<Product, ProductDto>(); var dto = _mapper.Map<ProductDto>(product); Example code DTOs decouple internal mo…
Short answer: Avoid breaking changes to existing endpoints. Use new versions for changes in contracts. Maintain old versions as long as needed. Ensure documentation and clients are updated accordingly. Real-world example…
Short answer: Return 409 Conflict if concurrency exception is caught. Model Binding & Validation Example code Use RowVersion / ETag to detect concurrent edits. Example with EF Core: modelBuilder.Entity<Product>…
Short answer: SP.NET Core automatically binds data based on parameter types and attributes ([FromBody], [FromQuery], etc.). Real-world example (ShopNest) ShopNest registers AppDbContext as Scoped and IMemoryCache as Sing…
Short answer: Model binding in ASP.NET Core maps incoming HTTP data to C# parameters or model properties. 🔍 Sources considered: Route data Query string Form data Headers JSON body (application/json) Uploaded files Servi…
Short answer: Simple types (int, string, bool, DateTime, etc.): Bound from route, query string, or form fields. Complex types (custom classes): Bound from multiple sources like query/form fields or JSON body. public IAct…
Short answer: Use a custom model binder when default binding doesn’t work (e.g., custom formats, headers). public class CustomBinder : IModelBinder { Example code public Task BindModelAsync(ModelBindingContext context) {…
Short answer: [FromQuery], etc.) You cannot bind multiple [FromBody] parameters in a single action. Common sources: [FromBody] — for JSON/XML payloads [FromQuery] — query string [FromRoute] — route values [FromForm] — fo…
Short answer: Decorate models with attributes: public class User { [Required] [StringLength(50)] [EmailAddress] public string Email { get; set; } } Used in both MVC and API for validation. Example code Decorate models wi…
Short answer: Server-side: Always performed on the server; use ModelState.IsValid. Client-side: HTML5 + jQuery Unobtrusive Validation (for MVC/Razor Pages). Client-side validation improves UX, but server-side is essentia…
Short answer: Create custom rules by inheriting ValidationAttribute: public class MustBeEvenAttribute : ValidationAttribute { public override bool IsValid(object value) { return (int)value % 2 == 0; } } Use like: [MustBe…
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: For large uploads, use IFormFile, Stream, or read from Request.Body for streaming. For downloads, return FileStreamResult. Enable buffering or streaming to avoid memory overload.
For large uploads, use IFormFile, Stream, or read from Request.Body for streaming. For downloads, return FileStreamResult. Enable buffering or streaming to avoid memory overload.
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.UseExceptionHandler(config => { config.Run(async context => { // Log and return problem details }); }); Or use ProblemDetails for structured error responses.
pp.UseExceptionHandler(config => { config.Run(async context => { // Log and return problem details }); }); Or use ProblemDetails for structured error responses. pp.UseExceptionHandler(config => { config.Run(async context => { // Log and return problem details }); }); Or use ProblemDetails for structured error responses. pp.UseExceptionHandler(config => { config.Run(async context => { // Log and return problem details }); }); Or use ProblemDetails for structured error responses.
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 UseExceptionHandler middleware or custom ExceptionMiddleware. You can also create a global error handler: app.UseExceptionHandler(config => { config.Run(async context => { // Log and return problem details }); }); Or use ProblemDetails for structured error responses.
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: Use proper status codes: 200 OK (success) 201 Created (on POST) 204 No Content (on DELETE) 400 Bad Request 401 Unauthorized / 403 Forbidden 404 Not Found 500 Internal Server Error return Ok(result);
return NotFound();
return BadRequest(ModelState);
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: ActionResult<T>: Combines a return value and response code. public ActionResult<Product> Get(int id) { ... } IActionResult: More flexible, returns different result types explicitly. Prefer ActionResult<T> for simpler, strongly-typed APIs.
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: ASP.NET Core supports full async/await pattern for IO-bound tasks. [HttpGet] public async Task<ActionResult<Product>> GetAsync(int id) {
var product = await _repo.GetAsync(id);
return product == null ? NotFound() : Ok(product);
} ✅ Improves scalability and performance.
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: NotFound() : Ok(product); ✅ Improves scalability and performance. NotFound() : Ok(product); ✅ Improves scalability and performance. NotFound() : Ok(product); ✅ Improves scalability and performance. NotFound() : Ok(product); ✅ Improves scalability and performance.
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: Enable CORS (Cross-Origin Resource Sharing) to allow client apps from different domains: services.AddCors(options => { options.AddPolicy("AllowFrontend", builder => builder.WithOrigins(" .AllowAnyHeader() .AllowAnyMethod()); }); app.UseCors("AllowFrontend");
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: ASP.NET Core doesn't include rate limiting out of the box (pre-.NET 8). Use libraries like: AspNetCoreRateLimit YARP, Azure API Management .NET 8 introduced built-in RateLimiterMiddleware.
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.UseSwagger(); pp.UseSwaggerUI(); Supports: Auto-generated OpenAPI docs Try it out interface Versioning support pp.UseSwagger(); pp.UseSwaggerUI(); Supports: Auto-generated OpenAPI docs Try it out interface Versioning support pp.UseSwagger(); pp.UseSwaggerUI(); Supports: Auto-generated OpenAPI docs Try it out interface Versioning support pp.UseSwagger();… pp.UseSwaggerUI(); Supports: Auto-generated OpenAPI docs…
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: Use Swashbuckle.AspNetCore or NSwag for generating Swagger docs. services.AddSwaggerGen(); app.UseSwagger(); app.UseSwaggerUI(); Supports: Auto-generated OpenAPI docs Try it out interface Versioning support
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: Unit testing: Mock services/repositories using Moq or FakeItEasy. Integration testing: Use WebApplicationFactory<T> + TestServer + HttpClient. var client = _factory.CreateClient();
var response = await client.GetAsync("/api/products");
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: Use JWT Bearer Tokens for stateless auth: services.AddAuthentication(JwtBearerDefaults.AuthenticationSch eme) .AddJwtBearer(options => { ... }); Secure endpoints with: [Authorize(Roles = "Admin")] OAuth supported via IdentityServer, Azure AD, or external providers.
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: HTTPS: Enforced via UseHttpsRedirection() CORS: Limit origins using policies Anti-forgery: Usually not needed for APIs unless using cookies (use ValidateAntiForgeryToken) Use authentication + authorization checks for all endpoints
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: DTOs decouple internal models from API contracts. Use AutoMapper for mapping: CreateMap<Product, ProductDto>(); var dto = _mapper.Map<ProductDto>(product);
DTOs decouple internal models from API contracts. Use AutoMapper for mapping: CreateMap<Product, ProductDto>(); var dto = _mapper.Map<ProductDto>(product);
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: Avoid breaking changes to existing endpoints. Use new versions for changes in contracts. Maintain old versions as long as needed. Ensure documentation and clients are updated accordingly.
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: Return 409 Conflict if concurrency exception is caught. Model Binding & Validation
Use RowVersion / ETag to detect concurrent edits. Example with EF Core: modelBuilder.Entity<Product>() .Property(p => p.RowVersion).IsRowVersion();
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: SP.NET Core automatically binds data based on parameter types and attributes ([FromBody], [FromQuery], etc.).
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: Model binding in ASP.NET Core maps incoming HTTP data to C# parameters or model properties. 🔍 Sources considered: Route data Query string Form data Headers JSON body (application/json) Uploaded files Services (via [FromServices]) ASP.NET Core automatically binds data based on parameter types and attributes ([FromBody], [FromQuery], etc.).
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: Simple types (int, string, bool, DateTime, etc.): Bound from route, query string, or form fields. Complex types (custom classes): Bound from multiple sources like query/form fields or JSON body. public IActionResult Create([FromBody] Product product)
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: Use a custom model binder when default binding doesn’t work (e.g., custom formats, headers). public class CustomBinder : IModelBinder {
public Task BindModelAsync(ModelBindingContext context) { // Custom logic here }
} Register with [ModelBinder] or globally in Startup.
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: [FromQuery], etc.) You cannot bind multiple [FromBody] parameters in a single action. Common sources: [FromBody] — for JSON/XML payloads [FromQuery] — query string [FromRoute] — route values [FromForm] — form fields and file uploads [FromHeader] — HTTP headers
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: Decorate models with attributes: public class User { [Required] [StringLength(50)] [EmailAddress] public string Email { get; set; } } Used in both MVC and API for validation.
Decorate models with attributes: public class User { [Required] [StringLength(50)] [EmailAddress] public string Email { get; set; }
} Used in both MVC and API for validation.
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: Server-side: Always performed on the server; use ModelState.IsValid. Client-side: HTML5 + jQuery Unobtrusive Validation (for MVC/Razor Pages). Client-side validation improves UX, but server-side is essential for security.
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: Create custom rules by inheriting ValidationAttribute: public class MustBeEvenAttribute : ValidationAttribute { public override bool IsValid(object value) { return (int)value % 2 == 0; } } Use like: [MustBeEven] public int Number { get; set; }
Create custom rules by inheriting ValidationAttribute: public class MustBeEvenAttribute : ValidationAttribute {
public override bool IsValid(object value) {
return (int)value % 2 == 0;
}
} Use like: [MustBeEven] public int Number { get; set; }
A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.