Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: Razor Pages use handler methods: public class IndexModel : PageModel { Example code public void OnGet() { ... } public IActionResult OnPost() { ... } } You can use asp-page-handler="Update" for cu…
Short answer: Inject services into PageModel constructor: public IndexModel(IMyService service) { ... } Also available in Razor views via @inject: @inject ILogger<MyPage> Logger Real-world example (ShopNest) ShopNe…
Short answer: Reusable libraries that contain Razor views, pages, static files, etc. Share UI components across multiple projects. dotnet new razorclasslib Real-world example (ShopNest) A ShopNest checkout request flows…
Short answer: Used to organize large applications into sections (e.g., Admin, Customer). Each Area has its own Controllers/Views/Models. [Area("Admin")] public class DashboardController : Controller { ... } Say…
Short answer: Handled via: ASP.NET Core Middleware WebOptimizer, Gulp, or Webpack Static files in wwwroot/ Enable in Startup.cs: app.UseStaticFiles(); Example code Handled via: ASP.NET Core Middleware WebOptimizer, Gulp,…
Short answer: ASP.NET Core supports Razor by default. You can add support for custom view engines by implementing IViewEngine. Real-world example (ShopNest) A ShopNest checkout request flows through middleware, hits a mi…
Short answer: Use IStringLocalizer<T> or IViewLocalizer: @inject IViewLocalizer Localizer <h1>@Localizer["Welcome"]</h1> Add resource .resx files for each language. Real-world example (ShopNes…
Short answer: Performance: Very similar, both use Razor rendering. Simplicity: Razor Pages have less boilerplate for page-based UIs. Maintainability: Razor Pages better for small apps, MVC better for large, modular apps.…
Short answer: templates) Attribute Routing (Preferred): [Route("api/products")] [ApiController] public class ProductsController : ControllerBase { [HttpGet("{id}")] public IActionResult Get(int id) {…
Short answer: pplication/vnd.company.v1+json services.AddApiVersioning(options => { options.ReportApiVersions = true; options.AssumeDefaultVersionWhenUnspecified = true; options.DefaultApiVersion = new ApiVersion(1, 0…
Short answer: media type versioning) Use Microsoft.AspNetCore.Mvc.Versioning package. ✅ Supported methods: URL versioning: /api/v1/products Header versioning: X-API-Version: 1.0 Media Type versioning: Accept: application…
Short answer: ASP.NET Core selects the response format based on the Accept header. JSON is the default. To add XML: services.AddControllers() .AddXmlSerializerFormatters(); Accept: application/xml Real-world example (Sho…
Short answer: SP.NET Core infers the source when possible. Real-world example (ShopNest) ShopNest registers AppDbContext as Scoped and IMemoryCache as Singleton. Putting DbContext in a Singleton causes threading bugs. Sa…
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…
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Razor Pages use handler methods: public class IndexModel : PageModel {
public void OnGet() { ... }
public IActionResult OnPost() { ... }
} You can use asp-page-handler="Update" for custom methods.
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: Inject services into PageModel constructor: public IndexModel(IMyService service) { ... } Also available in Razor views via @inject: @inject ILogger<MyPage> Logger
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: Reusable libraries that contain Razor views, pages, static files, etc. Share UI components across multiple projects. dotnet new razorclasslib
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: Used to organize large applications into sections (e.g., Admin, Customer). Each Area has its own Controllers/Views/Models. [Area("Admin")] public class DashboardController : Controller { ... }
ASP.NET Core ASP.NET Core Tutorial · ASP.NET Core
Short answer: Handled via: ASP.NET Core Middleware WebOptimizer, Gulp, or Webpack Static files in wwwroot/ Enable in Startup.cs: app.UseStaticFiles();
Handled via: ASP.NET Core Middleware WebOptimizer, Gulp, or Webpack Static files in wwwroot/ Enable in Startup.cs: app.UseStaticFiles();
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 Razor by default. You can add support for custom view engines by implementing IViewEngine.
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 IStringLocalizer<T> or IViewLocalizer: @inject IViewLocalizer Localizer <h1>@Localizer["Welcome"]</h1> Add resource .resx files for each language.
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: Performance: Very similar, both use Razor rendering. Simplicity: Razor Pages have less boilerplate for page-based UIs. Maintainability: Razor Pages better for small apps, MVC better for large, modular apps. Web API (RESTful Services) Web API (RESTful Services)
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: templates) Attribute Routing (Preferred): [Route("api/products")] [ApiController] public class ProductsController : ControllerBase { [HttpGet("{id}")] public IActionResult Get(int id) { ... } } Route Templates: Use placeholders like {id}, constraints like {id:int}. You can also define route prefixes at controller level and use relative routes in actions.
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: pplication/vnd.company.v1+json services.AddApiVersioning(options => { options.ReportApiVersions = true; options.AssumeDefaultVersionWhenUnspecified = true; options.DefaultApiVersion = new ApiVersion(1, 0); }); pplication/vnd.company.v1+json services.AddApiVersioning(options => { options.ReportApiVersions = true;… options.AssumeDefaultVersionWhenUnspecified…… = true; options.DefaultApiVersion = new ApiVersion(1, 0);…
}); pplication/vnd.company.v1+json services.AddApiVersioning(options => { options.ReportApiVersions = true; options.AssumeDefaultVersionWhenUnspecified = true; options.DefaultApiVersion = new ApiVersion(1, 0); }); pplication/vnd.company.v1+json services.AddApiVersioning(options => { options.ReportApiVersions = true;… options.AssumeDefaultVersionWhenUnspecified = true; options.DefaultApiVersion = new ApiVersion(1, 0); });
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: media type versioning) Use Microsoft.AspNetCore.Mvc.Versioning package. ✅ Supported methods: URL versioning: /api/v1/products Header versioning: X-API-Version: 1.0 Media Type versioning: Accept: application/vnd.company.v1+json services.AddApiVersioning(options => { options.ReportApiVersions = true;
options.AssumeDefaultVersionWhenUnspecified = true;
options.DefaultApiVersion = new ApiVersion(1, 0); });
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 selects the response format based on the Accept header. JSON is the default. To add XML: services.AddControllers() .AddXmlSerializerFormatters(); Accept: application/xml
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 infers the source when possible.
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: 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.