Interview Q&A

Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.

4608 total questions 4508 technical 100 career & HR 4272 from PDF library

Showing 326–350 of 3281

Career & HR topics

By tech stack

Popular tracks

Mid PDF
Anti-Forgery Tokens ● Protects against CSRF attacks ● In Razor: <form method="post"> @Html.AntiForgeryToken() </form> ● In API: use services.AddAntiforgery(), validate via [ValidateAntiForgeryToken]. 1⃣

Short answer: Anti-Forgery Tokens Protects against CSRF attacks In Razor: &lt;form method=&quot;post&quot;&gt; @Html.AntiForgeryToken() &lt;/form&gt; In API: use services.AddAntiforgery(), validate via [ValidateAntiForge…

Mid PDF
How to create REST APIs in ASP.NET Core?

Short answer: Creating REST APIs in ASP.NET Core is straightforward using controllers or minimal PIs. Explain a bit more Example: Traditional Controller-Based API dotnet new webapi -n MyApi Program.cs: var builder = WebA…

Mid PDF
Configure middleware: var app = builder.Build();?

Short answer: pp.UseAuthentication(); pp.UseAuthorization(); pp.UseAuthentication(); pp.UseAuthorization(); pp.UseAuthentication(); pp.UseAuthorization(); pp.UseAuthentication(); pp.UseAuthorization(); Real-world example…

Mid PDF
Explain ASP.NET Core Identity.

Short answer: ASP.NET Core Identity is a membership system that manages users, passwords, roles, claims, and authentication. Explain a bit more It provides: User registration &amp; login Password hashing Role &amp; claim…

Mid PDF
Explain built-in dependency injection in ASP.NET Core.

Short answer: If you change appsettings.json and configuration reload is enabled, IOptionsMonitor picks up the new value without restarting the app. Entity Framework Core Real-world example (ShopNest) ShopNest admin scre…

Mid PDF
Explain the MVC pattern.

Short answer: MVC stands for Model–View–Controller, a design pattern that separates application logic into three layers: Model – Represents the data and business logic (e.g., Product, Customer, Order). View – The UI or p…

Mid PDF
Publish the app via Visual Studio, CLI, or GitHub Actions.?

Short answer: dotnet publish -c Release Real-world example (ShopNest) ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely. Say this in the interview Define — one…

Mid PDF
Run Redis (e.g., Docker: docker run -p 6379:6379 redis).?

Short answer: Install package: dotnet add package Microsoft.Extensions.Caching.StackExchangeRedis Real-world example (ShopNest) ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers…

Mid PDF
How do you implement caching in ASP.NET Core?

Short answer: Caching improves performance by storing frequently used data in memory or external storage to reduce database or API calls. SP.NET Core provides: Real-world example (ShopNest) ShopNest admin screens use MVC…

Mid PDF
How to create REST APIs in ASP.NET Core? Follow :

Short answer: Creating REST APIs in ASP.NET Core is straightforward using controllers or minimal APIs. Explain a bit more Traditional Controller-Based API dotnet new webapi -n MyApi Program.cs: var builder = WebApplicati…

Mid PDF
Error / exception handling patterns?

Short answer: Use global exception handling middleware. Return meaningful HTTP status codes and error details. Avoid leaking sensitive info. Implement retry policies for transient errors. Real-world example (ShopNest) A…

ASP.NET Core Read answer
Mid PDF
Graceful shutdown?

Short answer: Handle shutdown signals to complete ongoing requests. Dispose resources correctly. Use IHostApplicationLifetime events to hook into shutdown process. Real-world example (ShopNest) A ShopNest checkout reques…

ASP.NET Core Read answer
Mid PDF
Handling secrets securely?

Short answer: Use Azure Key Vault, AWS Secrets Manager, or HashiCorp Vault. Avoid storing secrets in code or config files. Use environment variables or user secrets during development. Real-world example (ShopNest) A Sho…

ASP.NET Core Read answer
Mid PDF
Use of configuration and environment variables in CI/CD?

Short answer: Inject config via environment variables or secret stores in pipelines. Use multiple config files per environment (appsettings.Development.json). Secure sensitive values using CI/CD secret management. Real-w…

ASP.NET Core Read answer
Mid PDF
Internationalization / localization?

Short answer: Use resource files (.resx) for strings. Configure RequestLocalizationMiddleware. Support multiple cultures and fallback cultures. Localize data formats, dates, currencies. Real-world example (ShopNest) A Sh…

ASP.NET Core Read answer
Mid PDF
Validation of inputs to avoid security vulnerabilities (e.g. SQL?

Short answer: injection, XSS etc) Use parameterized queries / ORM to prevent SQL injection. Sanitize and encode user input to prevent XSS. Validate inputs rigorously on server side. Use built-in validation attributes and…

ASP.NET Core Read answer
Mid PDF
How to migrate an ASP.NET Core application from .NET 5 to .NET 8 (or newer)?

Short answer: Update target framework in project file (net8.0). Update NuGet packages and dependencies. Adapt code for minimal APIs if desired. Replace Startup with minimal hosting model if preferred. Test thoroughly for…

ASP.NET Core Read answer
Mid PDF
How do you handle version conflicts (e.g., multiple dependencies needing different versions of a library)?

Short answer: Use binding redirects (in .NET Framework). Use assembly version unification and strong-named assemblies. In .NET Core, resolve via NuGet package management, use central package versions. Consider upgrading…

ASP.NET Core Read answer
Mid PDF
Difference between conventional routing and attribute routing?

Short answer: Conventional routing: Routes defined centrally (usually in Startup), patterns applied globally. Attribute routing: Routes declared directly on controllers/actions via attributes ([Route], [HttpGet]). Attrib…

ASP.NET Core Read answer
Mid PDF
How to enable OpenAPI / Swagger UI and customizing it

Short answer: Add Swashbuckle.AspNetCore NuGet package. Configure Swagger services (builder.Services.AddSwaggerGen()). Enable middleware (app.UseSwagger(), app.UseSwaggerUI()). Customize with options like API info, docum…

ASP.NET Core Read answer
Mid PDF
How to return custom error responses / use custom middleware for

Short answer: error responses Implement custom exception handling middleware. Catch exceptions, set HTTP status, and return custom JSON payload. Use UseExceptionHandler() or global filters. Customize ProblemDetails or yo…

ASP.NET Core Read answer
Mid PDF
Using cancellation tokens in API controllers or actions?

Short answer: Accept CancellationToken parameter in action methods. Pass token to async calls to support request cancellation. Improves responsiveness and resource management. Real-world example (ShopNest) A ShopNest che…

ASP.NET Core Read answer
Mid PDF
What are the default limits for file upload sizes, and how to

Short answer: configure them Default max request body size is 30 MB. Configure via RequestSizeLimit attribute or KestrelServerOptions.Limits.MaxRequestBodySize. For IIS, adjust maxAllowedContentLength. Real-world example…

ASP.NET Core Read answer
Mid PDF
How to enable gzip or brotli compression

Short answer: Add ResponseCompression middleware. Register compression providers (AddResponseCompression()) in Program.cs. Configure supported MIME types and compression level. Real-world example (ShopNest) A ShopNest ch…

ASP.NET Core Read answer
Mid PDF
Working with JSON options: System.Text.Json vs Newtonsoft.Json?

Short answer: System.Text.Json: Default in .NET Core 3+, fast, built-in, less feature-rich. Newtonsoft.Json: More mature, supports advanced scenarios (e.g., polymorphic deserialization). Can switch to Newtonsoft by addin…

ASP.NET Core Read answer

ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC

Short answer: Anti-Forgery Tokens Protects against CSRF attacks In Razor: <form method="post"> @Html.AntiForgeryToken() </form> In API: use services.AddAntiforgery(), validate via [ValidateAntiForgeryToken]. 1⃣

Real-world example (ShopNest)

ShopNest’s product edit form posts to an MVC action. Model binding fills a ProductEditVm; the action validates and redisplay the view on errors.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC

Short answer: Creating REST APIs in ASP.NET Core is straightforward using controllers or minimal PIs.

Explain a bit more

Example: Traditional Controller-Based API dotnet new webapi -n MyApi Program.cs: var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); var app = builder.Build(); pp.MapControllers(); pp.Run(); Controller: [ApiController] [Route("api/[controller]")] public class ProductsController : ControllerBase { [HttpGet] public IActionResult GetAll() => Ok(new[] { "Laptop", "Phone" }); } ✅ You get RESTful endpoints automatically (GET /api/products). {

Example code

if (!ModelState.IsValid)
return BadRequest(ModelState);
return CreatedAtAction(nameof(CreateOrder), new { id = 1 }, order); }
} 📦 3. How does content negotiation work? Content negotiation allows clients to request responses in a specific format (JSON, XML, etc.) using the Accept header. SP.NET Core automatically picks the best formatter: GET /api/products ccept: application/json Response → JSON GET /api/products ccept: application/xml Response → XML (if XML formatter is added) Enable XML Support: builder.Services.AddControllers() .AddXmlSerializerFormatters(); 🧭 4. How to handle versioning in APIs? You can version APIs to maintain backward compatibility using the Microsoft.AspNetCore.Mvc.Versioning package. Install: dotnet add package Microsoft.AspNetCore.Mvc.Versioning Configure: builder.Services.AddApiVersioning(options => {
options.DefaultApiVersion = new ApiVersion(1, 0);
options.AssumeDefaultVersionWhenUnspecified = true;
{ [HttpGet] public IActionResult Get() => Ok("Version 1");
} ⚠ 5. What is ProblemDetails? ProblemDetails is a standardized JSON structure for API error responses (RFC 7807). Example Output: { "type": " "title": "Resource not found", "status": 404, "detail": "Product with ID 5 was not found" } Usage: return NotFound(new ProblemDetails
{ Title = "Product not found", Status = StatusCodes.Status404NotFound, Detail = "The product ID 5 does not exist." }); 🚦 6. How to return custom HTTP status codes? You can use built-in helpers from ControllerBase: Method Status Code Ok() 200 Created() / CreatedAtAction() 201 NoContent() 204 BadRequest() 400 Unauthorized() 401 NotFound() 404 StatusCode(500) Custom Example: return StatusCode(503, "Service temporarily unavailable"); 📄 7. How to implement pagination in APIs? Pagination helps manage large datasets efficiently. Example: [HttpGet] public IActionResult GetProducts([FromQuery] int page = 1, [FromQuery] int size = 10) {
var data = _context.Products .Skip((page - 1) * size) .Take(size) .ToList(); var totalCount = _context.Products.Count(); Response.Headers.Add("X-Total-Count", totalCount.ToString()); return Ok(data);
} ✅ Supports GET /api/products?page=2&size=5. 🔐 8. How to secure APIs with JWT tokens? Use JWT (JSON Web Token) authentication for stateless security. Setup in Program.cs: builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationS cheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = " ValidateAudience = true, ValidAudience = " IssuerSigningKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes("super-secret-key")) }; }); Then protect controllers: [Authorize] [ApiController] [Route("api/[controller]")] public class OrdersController : ControllerBase
{ [HttpGet] public IActionResult GetOrders() => Ok("Secure data");
} ⚡ 9. What is rate limiting in .NET 8? .NET 8 introduces built-in rate limiting middleware to control API request rates. Example: builder.Services.AddRateLimiter(options => { options.AddFixedWindowLimiter("fixed", opt => {
opt.PermitLimit = 5; // 5 requests
opt.Window = TimeSpan.FromSeconds(10); // per 10 seconds
var exception = context.Features.Get<IExceptionHandlerFeature>()?.Error; return Results.Problem(title: "Unexpected error", detail: exception?.Message); }); Or write a custom middleware for consistent error formatting. 🧾 11. How to use Swagger / OpenAPI? Swagger generates interactive API documentation automatically. Setup: builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); var app = builder.Build();
if (app.Environment.IsDevelopment())
{ pp.UseSwagger(); pp.UseSwaggerUI(); } Run → Navigate to ✅ You can test endpoints directly from the browser. 🧰 12. What is NSwag or Swashbuckle? Both tools generate OpenAPI/Swagger documentation, but with slight differences: Tool Description Swashbuckle.AspNetCor Most common; adds Swagger UI, docs, and JSON schema NSwag Adds extra features like client SDK generation for C#/TypeScript Example (NSwag client generation): nswag openapi2csclient /input: /output:Client.cs 📤 13. How to upload files via Web API? Use IFormFile for file uploads. Controller Example: [HttpPost("upload")] public async Task<IActionResult> UploadFile(IFormFile file)
{
if (file == null || file.Length == 0)
return BadRequest("No file uploaded.");
var path = Path.Combine("wwwroot/uploads", file.FileName);
using var stream = new FileStream(path, FileMode.Create); wait file.CopyToAsync(stream); return Ok(new { file.FileName, file.Length });
} Client sends multipart/form-data POST requests. 🌐 14. How to implement CORS? CORS (Cross-Origin Resource Sharing) allows requests from other domains (e.g., frontend pps). Enable in Program.cs: builder.Services.AddCors(options => { options.AddPolicy("AllowReactApp", policy => policy.WithOrigins(" .AllowAnyHeader() .AllowAnyMethod()); }); var app = builder.Build(); pp.UseCors("AllowReactApp"); ✅ Now your React or Angular frontend can call your API safely. 🚀 15. What’s new in .NET 8 Minimal APIs? Minimal APIs let you build lightweight REST endpoints without controllers — great for microservices. Example: var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

Real-world example (ShopNest)

ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC

Short answer: pp.UseAuthentication(); pp.UseAuthorization(); pp.UseAuthentication(); pp.UseAuthorization(); pp.UseAuthentication(); pp.UseAuthorization(); pp.UseAuthentication(); pp.UseAuthorization();

Real-world example (ShopNest)

ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC

Short answer: ASP.NET Core Identity is a membership system that manages users, passwords, roles, claims, and authentication.

Explain a bit more

It provides: User registration & login Password hashing Role & claims management Two-factor authentication Cookie & token-based authentication You can scaffold Identity to get ready-to-use pages for login, registration, and password reset. ASP.NET Core Identity is a membership system that manages users, passwords, roles, claims, and authentication. It provides: User registration & login Password hashing Role & claims management Two-factor authentication Cookie & token-based authentication

Example code

You can scaffold Identity to get ready-to-use pages for login, registration, and password reset. ASP.NET Core Identity is a membership system that manages users, passwords, roles, claims, and authentication. It provides: User registration & login Password hashing Role & claims management Two-factor authentication Cookie & token-based authentication Example: You can scaffold Identity to get ready-to-use pages for login, registration, and password reset. ⚙ 2. How do you configure Identity in ASP.NET Core? Add Identity services in Program.cs: builder.Services.AddDbContext<AppDbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("Defa ultConnection"))); builder.Services.AddIdentity<ApplicationUser, IdentityRole>() .AddEntityFrameworkStores<AppDbContext>() .AddDefaultTokenProviders(); ASP.NET Core Identity is a membership system that manages users, passwords, roles, claims, and authentication. It provides: User registration & login Password hashing Role & claims management Two-factor authentication Cookie & token-based authentication Example: You can scaffold Identity to get ready-to-use pages for login, registration, and password reset. ⚙ 2. How do you configure Identity in ASP.NET Core? Add Identity services in Program.cs: builder.Services.AddDbContext<AppDbContext>(options => options.UseSqlServer(builder.Configuration.GetConnectionString("Defa ultConnection"))); builder.Services.AddIdentity<ApplicationUser, IdentityRole>() .AddEntityFrameworkStores<AppDbContext>() .AddDefaultTokenProviders();

Real-world example (ShopNest)

ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC

Short answer: If you change appsettings.json and configuration reload is enabled, IOptionsMonitor picks up the new value without restarting the app. Entity Framework Core

Real-world example (ShopNest)

ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC

Short answer: MVC stands for Model–View–Controller, a design pattern that separates application logic into three layers: Model – Represents the data and business logic (e.g., Product, Customer, Order). View – The UI or presentation layer that displays data (Razor views). {

Example code

public IActionResult Details(int id)
{
var product = _service.GetById(id);
return View(product);
}
} Notes: Action methods cannot be private or static. They respond to routes like /Product/Details/5. 🎯 6. What are Action Results? An Action Result represents the response returned to the client — view, JSON, redirect, file, etc. SP.NET Core provides many result types: ViewResult JsonResult RedirectResult FileResult ContentResult StatusCodeResult 🔍 7. Difference between ViewResult, JsonResult, and ContentResult. Type Used For Example ViewResult Returns an HTML view return View("Details", model); JsonResult Returns JSON data return Json(model); ContentResul Returns plain text or custom content return Content("Hello World"); IActionResult is an interface that represents the result of an action method. It allows flexibility — you can return any kind of result (view, JSON, redirect, etc.) from the same method. Example: public IActionResult Index()
{
if (!User.Identity.IsAuthenticated)
return RedirectToAction("Login");
return View();
} 🧠 9. How does model binding work? Model binding automatically maps data from the HTTP request (query string, route, body, form) to method parameters or model objects. Example: public IActionResult Save(Product model)
{ // model properties are automatically filled _service.Add(model); return RedirectToAction("Index");
}
{ [Required] public string Name { get; set; } [Range(1, 10000)] public decimal Price { get; set; }
} In a controller: if (!ModelState.IsValid)
return View(model);

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC

Short answer: dotnet publish -c Release

Real-world example (ShopNest)

ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC

Short answer: Install package: dotnet add package Microsoft.Extensions.Caching.StackExchangeRedis

Real-world example (ShopNest)

ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC

Short answer: Caching improves performance by storing frequently used data in memory or external storage to reduce database or API calls. SP.NET Core provides:

Real-world example (ShopNest)

ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core MVC ASP.NET Core MVC Tutorial · MVC

Short answer: Creating REST APIs in ASP.NET Core is straightforward using controllers or minimal APIs.

Explain a bit more

Traditional Controller-Based API dotnet new webapi -n MyApi Program.cs: var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); var app = builder.Build(); app.MapControllers(); app.Run(); Controller: [ApiController] [Route("api/[controller]")] public class ProductsController : ControllerBase [HttpGet] public IActionResult GetAll() => Ok(new[] { "Laptop", "Phone" }); ✅ You get RESTful endpoints automatically (GET /api/products). Creating REST APIs in ASP.NET Core is straightforward using controllers or minimal APIs.

Example code

Traditional Controller-Based API dotnet new webapi -n MyApi Program.cs: var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); var app = builder.Build(); app.MapControllers(); app.Run(); Controller: [ApiController] [Route("api/[controller]")] public class ProductsController : ControllerBase [HttpGet] public IActionResult GetAll() => Ok(new[] { "Laptop", "Phone" }); ✅ You get RESTful endpoints automatically (GET /api/products). Creating REST APIs in ASP.NET Core is straightforward using controllers or minimal APIs. Example: Traditional Controller-Based API dotnet new webapi -n MyApi Program.cs: var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); var app = builder.Build(); app.MapControllers(); app.Run(); Controller: [ApiController] [Route("api/[controller]")] public class ProductsController : ControllerBase [HttpGet] public IActionResult GetAll() => Ok(new[] { "Laptop", "Phone" }); ✅ You get RESTful endpoints automatically (GET /api/products). Creating REST APIs in ASP.NET Core is straightforward using controllers or minimal APIs. Example: Traditional Controller-Based API dotnet new webapi -n MyApi Program.cs: var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); var app = builder.Build(); app.MapControllers(); app.Run(); Controller: [ApiController] [Route("api/[controller]")] public class ProductsController : ControllerBase [HttpGet] public IActionResult GetAll() => Ok(new[] { "Laptop", "Phone" }); ✅ You get RESTful endpoints automatically (GET /api/products). 🧱 2. What is the [ApiController] attribute? [ApiController] simplifies building APIs by adding smart defaults: Automatic model validation → 400 Bad Request on invalid models Automatic [FromBody], [FromQuery], etc. inference Follow : ProblemDetails JSON response for errors Example: [ApiController] [Route("api/[controller]")] public class OrdersController : ControllerBase [HttpPost] public IActionResult CreateOrder(Order order) if (!ModelState.IsValid) return BadRequest(ModelState); return CreatedAtAction(nameof(CreateOrder), new { id = 1 }, order); 📦 3. How does content negotiation work? Content negotiation allows clients to request responses in a specific format (JSON, XML, etc.) using the Accept header. ASP.NET Core automatically picks the best formatter: GET /api/products Accept: application/json Response → JSON GET /api/products Accept: application/xml Response → XML (if XML formatter is added) Follow : Enable XML Support: builder.Services.AddControllers() .AddXmlSerializerFormatters(); 🧭 4. How to handle versioning in APIs? You can version APIs to maintain backward compatibility using the Microsoft.AspNetCore.Mvc.Versioning package. Install: dotnet add package Microsoft.AspNetCore.Mvc.Versioning Configure: builder.Services.AddApiVersioning(options => options.DefaultApiVersion = new ApiVersion(1, 0); options.AssumeDefaultVersionWhenUnspecified = true; options.ReportApiVersions = true; }); Use in controllers: [ApiVersion("1.0")] [Route("api/v{version:apiVersion}/products")] [ApiController] public class ProductsV1Controller : ControllerBase [HttpGet] public IActionResult Get() => Ok("Version 1"); ⚠ 5. What is ProblemDetails? Follow : ProblemDetails is a standardized JSON structure for API error responses (RFC 7807). Example Output: "type": " "title": "Resource not found", "status": 404, "detail": "Product with ID 5 was not found" Usage: return NotFound(new ProblemDetails Title = "Product not found", Status = StatusCodes.Status404NotFound, Detail = "The product ID 5 does not exist." }); 🚦 6. How to return custom HTTP status codes? You can use built-in helpers from ControllerBase: Method Status Code Ok() 200 Created() / CreatedAtAction() 201 NoContent() 204 BadRequest() 400 Unauthorized() 401 Follow : NotFound() 404 StatusCode(500) Custom Example: return StatusCode(503, "Service temporarily unavailable"); 📄 7. How to implement pagination in APIs? Pagination helps manage large datasets efficiently. Example: [HttpGet] public IActionResult GetProducts([FromQuery] int page = 1, [FromQuery] int size = 10) var data = _context.Products .Skip((page - 1) * size) .Take(size) .ToList(); var totalCount = _context.Products.Count(); Response.Headers.Add("X-Total-Count", totalCount.ToString()); return Ok(data); ✅ Supports GET /api/products?page=2&size=5. 🔐 8. How to secure APIs with JWT tokens? Use JWT (JSON Web Token) authentication for stateless security. Follow : Setup in Program.cs: builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationS cheme) .AddJwtBearer(options => options.TokenValidationParameters = new TokenValidationParameters ValidateIssuer = true, ValidIssuer = " ValidateAudience = true, ValidAudience = " IssuerSigningKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes("super-secret-key")) }); Then protect controllers: [Authorize] [ApiController] [Route("api/[controller]")] public class OrdersController : ControllerBase [HttpGet] public IActionResult GetOrders() => Ok("Secure data"); ⚡ 9. What is rate limiting in .NET 8? .NET 8 introduces built-in rate limiting middleware to control API request rates. Example: builder.Services.AddRateLimiter(options => Follow : options.AddFixedWindowLimiter("fixed", opt => opt.PermitLimit = 5; // 5 requests opt.Window = TimeSpan.FromSeconds(10); // per 10 seconds opt.QueueLimit = 0; }); }); var app = builder.Build(); app.UseRateLimiter(); app.MapGet("/api/data", () => "Hello") .RequireRateLimiting("fixed"); ✅ Prevents abuse or DDoS attacks by throttling requests. 🚨 10. How do you handle exceptions in APIs? Use global exception handling middleware instead of try/catch everywhere. Example: app.UseExceptionHandler("/error"); app.Map("/error", (HttpContext context) => var exception = context.Features.Get<IExceptionHandlerFeature>()?.Error; return Results.Problem(title: "Unexpected error", detail: exception?.Message); }); Or write a custom middleware for consistent error formatting. Follow : 🧾 11. How to use Swagger / OpenAPI? Swagger generates interactive API documentation automatically. Setup: builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); var app = builder.Build(); if (app.Environment.IsDevelopment()) app.UseSwagger(); app.UseSwaggerUI(); Run → Navigate to ✅ You can test endpoints directly from the browser. 🧰 12. What is NSwag or Swashbuckle? Both tools generate OpenAPI/Swagger documentation, but with slight differences: Tool Description Swashbuckle.AspNetCor Most common; adds Swagger UI, docs, and JSON schema NSwag Adds extra features like client SDK generation for C#/TypeScript Example (NSwag client generation): Follow : nswag openapi2csclient /input: /output:Client.cs 📤 13. How to upload files via Web API? Use IFormFile for file uploads. Controller Example: [HttpPost("upload")] public async Task<IActionResult> UploadFile(IFormFile file) if (file == null || file.Length == 0) return BadRequest("No file uploaded."); var path = Path.Combine("wwwroot/uploads", file.FileName); using var stream = new FileStream(path, FileMode.Create); await file.CopyToAsync(stream); return Ok(new { file.FileName, file.Length }); Client sends multipart/form-data POST requests. 🌐 14. How to implement CORS? CORS (Cross-Origin Resource Sharing) allows requests from other domains (e.g., frontend apps). Enable in Program.cs: builder.Services.AddCors(options => Follow : options.AddPolicy("AllowReactApp", policy => policy.WithOrigins(" .AllowAnyHeader() .AllowAnyMethod()); }); var app = builder.Build(); app.UseCors("AllowReactApp"); ✅ Now your React or Angular frontend can call your API safely. 🚀 15. What’s new in .NET 8 Minimal APIs? Minimal APIs let you build lightweight REST endpoints without controllers — great for microservices. Example: var builder = WebApplication.CreateBuilder(args); var app = builder.Build(); app.MapGet("/products", () => new[] { "Phone", "Tablet" }); app.MapPost("/products", (Product product) => Results.Created($"/products/{product.Id}", product)); app.Run(); New in .NET 8: Route groups for grouping endpoints Input validation with [Validate] attributes Enhanced OpenAPI (Swagger) support Rate limiting, Authorization, and Filters integration Follow : Typed results for consistent HTTP responses ✅ Minimal APIs now rival traditional controllers for small, fast APIs. Performance & Caching

Real-world example (ShopNest)

ShopNest admin screens use MVC: controller loads data, Razor view renders HTML, Tag Helpers build forms safely.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: Use global exception handling middleware. Return meaningful HTTP status codes and error details. Avoid leaking sensitive info. Implement retry policies for transient errors.

Real-world example (ShopNest)

A ShopNest ValidateModelAttribute runs before actions and returns 400 if ModelState is invalid—same rule for every controller.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: Handle shutdown signals to complete ongoing requests. Dispose resources correctly. Use IHostApplicationLifetime events to hook into shutdown process.

Real-world example (ShopNest)

A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: Use Azure Key Vault, AWS Secrets Manager, or HashiCorp Vault. Avoid storing secrets in code or config files. Use environment variables or user secrets during development.

Real-world example (ShopNest)

A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: Inject config via environment variables or secret stores in pipelines. Use multiple config files per environment (appsettings.Development.json). Secure sensitive values using CI/CD secret management.

Real-world example (ShopNest)

A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: Use resource files (.resx) for strings. Configure RequestLocalizationMiddleware. Support multiple cultures and fallback cultures. Localize data formats, dates, currencies.

Real-world example (ShopNest)

A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: injection, XSS etc) Use parameterized queries / ORM to prevent SQL injection. Sanitize and encode user input to prevent XSS. Validate inputs rigorously on server side. Use built-in validation attributes and custom validators. Sample / Misc Interview Questions

Real-world example (ShopNest)

A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: Update target framework in project file (net8.0). Update NuGet packages and dependencies. Adapt code for minimal APIs if desired. Replace Startup with minimal hosting model if preferred. Test thoroughly for API changes or obsoleted APIs. Review and update middleware and routing patterns.

Example code

Update target framework in project file (net8.0). Update NuGet packages and dependencies. Adapt code for minimal APIs if desired. Replace Startup with minimal hosting model if preferred. Test thoroughly for API changes or obsoleted APIs. Review and update middleware and routing patterns.

Real-world example (ShopNest)

A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: Use binding redirects (in .NET Framework). Use assembly version unification and strong-named assemblies. In .NET Core, resolve via NuGet package management, use central package versions. Consider upgrading or consolidating dependencies.

Real-world example (ShopNest)

ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: Conventional routing: Routes defined centrally (usually in Startup), patterns applied globally. Attribute routing: Routes declared directly on controllers/actions via attributes ([Route], [HttpGet]). Attribute routing is more flexible and explicit.

Real-world example (ShopNest)

ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: Add Swashbuckle.AspNetCore NuGet package. Configure Swagger services (builder.Services.AddSwaggerGen()). Enable middleware (app.UseSwagger(), app.UseSwaggerUI()). Customize with options like API info, document filters, UI themes.

Real-world example (ShopNest)

A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: error responses Implement custom exception handling middleware. Catch exceptions, set HTTP status, and return custom JSON payload. Use UseExceptionHandler() or global filters. Customize ProblemDetails or your own error models.

Real-world example (ShopNest)

ShopNest pipeline order matters: exception handling → HTTPS → auth → authorization → endpoints. Auth must run before protected APIs.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: Accept CancellationToken parameter in action methods. Pass token to async calls to support request cancellation. Improves responsiveness and resource management.

Real-world example (ShopNest)

A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: configure them Default max request body size is 30 MB. Configure via RequestSizeLimit attribute or KestrelServerOptions.Limits.MaxRequestBodySize. For IIS, adjust maxAllowedContentLength.

Real-world example (ShopNest)

A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: Add ResponseCompression middleware. Register compression providers (AddResponseCompression()) in Program.cs. Configure supported MIME types and compression level.

Real-world example (ShopNest)

A ShopNest checkout request flows through middleware, hits a minimal API or controller, uses scoped services, and returns ProblemDetails on errors.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share

ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core

Short answer: System.Text.Json: Default in .NET Core 3+, fast, built-in, less feature-rich. Newtonsoft.Json: More mature, supports advanced scenarios (e.g., polymorphic deserialization). Can switch to Newtonsoft by adding AddNewtonsoftJson() in MVC options.

Say this in the interview

  1. Define — one clear sentence (the short answer above).
  2. Example — relate it to a project like ShopNest or your real work.
  3. Trade-off — when you would not use it.
Permalink & share
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details