ASP.
NET Core — Quick Reference
Sample PDF for file result practice · May 2026
1. Controller Basics
A controller in [Link] Core must be a public class that inherits ControllerBase (for APIs) or
Controller (for MVC views). Annotate it with [ApiController] and [Route] to enable automatic model
binding, validation, and routing.
Minimal working controller:
[ApiController] [Route("api/[controller]")] public class ProductsController :
ControllerBase { [HttpGet("{id}")] public IActionResult GetById(int id) =>
Ok(new { Id = id, Name = "Widget" }); }
2. HTTP Action Verbs
Attribute HTTP Verb Typical Use
[HttpGet] GET Read / query data
[HttpPost] POST Create a resource
[HttpPut] PUT Replace a resource
[HttpPatch] PATCH Partial update
[HttpDelete] DELETE Remove a resource
3. Dependency Injection
Register services in [Link] using one of three lifetimes:
Lifetime Method When to use
Transient AddTransient<T>() Lightweight, stateless services
Scoped AddScoped<T>() Per-HTTP-request (e.g., DbContext)
Singleton AddSingleton<T>() Shared app-wide state / config
4. [Link] — Minimal API Setup
[Link] Core 6+ uses a single [Link] (no Startup class). The builder pattern wires services; the
app pipeline is configured with Use… extension methods.
var builder = [Link](args);
[Link]();
[Link](); [Link]();
var app = [Link](); if ([Link]())
[Link]().UseSwaggerUI(); [Link]();
[Link](); [Link](); [Link]();
5. Common Return Types
Return type Status code Example
Ok(value) 200 Successful GET
Created(uri,val) 201 POST created resource
NoContent() 204 Successful DELETE
BadRequest(msg) 400 Validation failure
NotFound() 404 Resource missing
StatusCode(n) any Custom codes
6. Quick Checklist
■ Controller class is public and inherits ControllerBase
■ [ApiController] attribute is present
■ Route template defined via [Route] or inside the verb attribute
■ Action methods declare an explicit HTTP verb ([HttpGet] etc.)
■ Services registered in [Link] before [Link]()
■ [Link]() called before [Link]()
Generated for file-result practice — [Link] Core 8 · .NET 8