controller
In ASP.NET Core, a class deriving from ControllerBase that groups related HTTP endpoints as methods called actions.
In more detail
Attributes on the class and actions declare routes, and ControllerBase supplies helpers such as Ok() and NotFound(). app.MapControllers() adds all controller routes to the app. Controllers suit large resource surfaces that benefit from conventions and filters.
Related terms
- action — A public method on a controller that handles requests for one route and returns a result.
- [ApiController] — An attribute that switches on web API conventions for a controller, including automatic 400 responses for invalid models and inferred binding sources.
- minimal API — An ASP.NET Core style that declares each route and its handler together, as in app.MapGet("/api/ping", () => Results.Ok("catalog")).
- attribute routing — Declaring a controller's routes with attributes such as [Route("api/products")] and [HttpGet("{id:int}")] on the class and its actions.
Taught in
- Classes, Interfaces, and Object-Oriented C# — Modern .NET Core, C# & Enterprise Microservices
- The ASP.NET Core Middleware Pipeline — Modern .NET Core, C# & Enterprise Microservices
- Building Routes with Controllers — Modern .NET Core, C# & Enterprise Microservices
- Comparing Controllers and Minimal APIs — Modern .NET Core, C# & Enterprise Microservices
- OpenTelemetry, Container Publishing and Trimming — Modern .NET Core, C# & Enterprise Microservices