Learn ASP.NET Core

Microsoft's fast, cross-platform framework for web APIs and services in C#

21 lessons · 4 hours · 4 levels · covers ASP.NET Core ASP.NET Core 10

ASP.NET Core is the open-source, cross-platform web framework of .NET for building HTTP APIs, web apps and real-time services in C#. It combines minimal APIs or MVC controllers with built-in dependency injection, configuration, logging, authentication and a very fast web server, Kestrel. It is a top choice for enterprise backends and cloud services, especially on Azure.

Before you start

ASP.NET Core builds on these; the tree links to the exact lessons you need.

How deep do you want to go?

1. EssentialsRead and write simple code, do the everyday basics7 lessons · 1 hour in total
2. PracticalUse it productively at work, with the usual idioms13 lessons · 3 hours in total
3. AdvancedThe less common features, performance and trade-offs18 lessons · 4 hours in total
4. ExpertInternals and the edge cases experts know21 lessons · 4 hours in total

The ASP.NET Core tree

ASP.NET CoreYour first ASP.NET Core appYour first ASP.NETCore appRouting and minimal API endpointsRouting and minimalAPI endpointsBinding request dataBinding request dataResponses and status codesResponses andstatus codesDependency injectionDependency injectionConfiguration and optionsConfiguration andoptionsThe middleware pipelineThe middlewarepipelineMVC controllers for APIsMVC controllers forAPIsData access with EF CoreData access with EFCoreValidation and error handlingValidation and errorhandlingLoggingLoggingOpenAPI documentsOpenAPI documentsIntegration testing with WebApplicationFactoryIntegration testingwith WebApplicatio…Namespaces, projects and NuGetNamespaces,projects and NuGetDelegates, lambdas and eventsDelegates, lambdasand eventsNull and nullable typesNull and nullabletypesRecordsRecordsInheritance and interfacesInheritance andinterfacesasync and awaitasync and awaitLINQLINQUnit testing with xUnitUnit testing withxUnitCancellation and parallelismCancellation andparallelismExtension methods and membersExtension methodsand membersJIT, tiered compilation and Native AOTJIT, tieredcompilation and Na…
Essentials and Practical shown (13 of 21 lessons); the full list is below. Click a lesson to read it.

All 21 lessons, in order

Getting started

  1. Your first ASP.NET Core app · Essentials · 10 min

    Create a web app with dotnet new web, understand Program.cs, the builder and the app, and run it with Kestrel.

Endpoints and HTTP

  1. Routing and minimal API endpoints · Essentials · 12 min

    Map HTTP methods and URL patterns to handlers with MapGet, MapPost and friends, using route parameters and constraints.

  2. Binding request data · Essentials · 12 min

    Get route values, query strings, headers, JSON bodies and services into handler parameters.

  3. Responses and status codes · Essentials · 10 min

    Return JSON, status codes and headers using plain objects, Results and TypedResults.

  4. MVC controllers for APIs · Practical · 12 min

    Build APIs with [ApiController] classes, attribute routing, ActionResult<T> and automatic model validation.

  5. Validation and error handling · Practical · 12 min

    Validate input with data annotations, and return consistent ProblemDetails for errors and exceptions.

  6. Route groups and endpoint filters · Advanced · 12 min

    Organize minimal APIs with MapGroup and add cross-cutting logic per endpoint with endpoint filters.

App building blocks

  1. Dependency injection · Essentials · 14 min

    Register services with singleton, scoped and transient lifetimes and receive them in handlers and constructors.

  2. Configuration and options · Essentials · 12 min

    Read settings from appsettings.json, environment variables and secrets, and bind them to typed options classes.

  3. The middleware pipeline · Essentials · 12 min

    Understand how requests flow through ordered middleware, write inline middleware and place built-in ones correctly.

  4. Logging · Practical · 10 min

    Write structured logs with ILogger<T>, message templates and log levels, and configure them per category.

  5. Background services · Advanced · 12 min

    Run long-lived work with BackgroundService, timers and queues, using scoped services safely and stopping gracefully.

Data and APIs

  1. Data access with EF Core · Practical · 15 min

    Map classes to database tables with Entity Framework Core: DbContext, migrations, LINQ queries and saving changes.

  2. OpenAPI documents · Practical · 10 min

    Generate an OpenAPI description of your API with Microsoft.AspNetCore.OpenApi and enrich it with endpoint metadata.

  3. Integration testing with WebApplicationFactory · Practical · 14 min

    Test the whole HTTP pipeline in memory with WebApplicationFactory, HttpClient and replaced services.

Security

  1. Authentication with JWT and cookies · Advanced · 15 min

    Identify users with authentication schemes, validate JWT bearer tokens and read claims from the user principal.

  2. Authorization policies · Advanced · 12 min

    Control access with RequireAuthorization, roles, claims-based policies and resource-based checks.

Production and performance

  1. Caching and rate limiting · Advanced · 14 min

    Speed up and protect APIs with output caching, HybridCache and the built-in rate limiting middleware.

  2. Kestrel, proxies and deployment · Expert · 15 min

    Configure Kestrel endpoints, limits and protocols, run behind reverse proxies with forwarded headers, and ship containers.

  3. Performance and Native AOT · Expert · 15 min

    Make APIs fast and lean with async I/O, IHttpClientFactory, JSON source generation, CreateSlimBuilder and Native AOT.

  4. Health checks and observability · Expert · 14 min

    Expose health endpoints and instrument the app with OpenTelemetry traces, metrics and logs.