ASP.NET Core Tutorial
Learn ASP.NET Core step by step: 52 lessons in 12 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is ASP.NET Core? Find out what ASP.NET Core is, how Kestrel and the request pipeline turn HTTP bytes into C# code, what ships with .NET 10, and how the examples here run.
- Your First Web App Build your first ASP.NET Core app: create the builder, map an endpoint, start Kestrel, call it with HttpClient and shut it down cleanly with StopAsync.
- Anatomy of a Project Tour an ASP.NET Core project file by file: Program.cs, the csproj and Web SDK, appsettings, launchSettings, wwwroot, plus the dotnet CLI commands you use daily.
- The Host and the Builder Understand WebApplicationBuilder and WebApplication: what CreateBuilder sets up, how services, configuration, logging and environment fit together, and Use vs Map.
Routing and Minimal APIs
- Minimal API Endpoints Write minimal API endpoints with MapGet, MapPost, MapPut and MapDelete, choose return types, and use Results and TypedResults to send correct status codes.
- Route Templates and Constraints Master ASP.NET Core route templates: parameters, optional and catch-all segments, defaults, constraints such as int, guid and regex, named routes and link generation.
- Route Groups and Organizing Endpoints Organize minimal API endpoints with MapGroup: shared prefixes, nested groups, group-wide filters and metadata, and one extension method per feature.
- Parameter Binding in Minimal APIs How minimal API handlers get their arguments: route, query, header, body, form and service binding, AsParameters, special types and what happens on failure.
- Responses, Results and Content Negotiation Return the right HTTP response from minimal API handlers: Results and TypedResults helpers, union return types, JSON options, files, streams and content negotiation.
- Endpoint Filters Wrap minimal API handlers with endpoint filters: AddEndpointFilter, IEndpointFilter classes, short-circuiting, validation filters and execution order.
Middleware and the Request Pipeline
- The Middleware Pipeline Understand the ASP.NET Core request pipeline: Use, Run, Map and MapWhen, the next delegate, why order matters, short-circuiting and terminal middleware.
- Writing Custom Middleware Write your own ASP.NET Core middleware: inline Use delegates, convention-based classes, IMiddleware, request timing and correlation id examples, and lifetimes.
- HttpContext, Request and Response Explore HttpContext in ASP.NET Core: request properties, headers, query strings, Items, features, reading bodies twice and the rules for when a response has started.
- Error Handling and Problem Details Handle errors in ASP.NET Core with UseExceptionHandler, IExceptionHandler, status code pages and RFC 9457 ProblemDetails, and know what the developer exception page shows.
- Static Files, Default Documents and CORS Serve static files in ASP.NET Core with UseStaticFiles, file providers, content types and cache headers, then configure CORS policies and understand preflight requests.
Dependency Injection, Configuration and Logging
- Dependency Injection in ASP.NET Core See how ASP.NET Core creates a service scope per request, where you can inject services, how lifetimes behave in a web app and how to avoid captive dependencies.
- Configuration and the Options Pattern Learn how ASP.NET Core layers configuration from JSON, environment variables and the command line, and read it with IOptions, IOptionsSnapshot and IOptionsMonitor.
- Environments and Secrets Understand ASPNETCORE_ENVIRONMENT, what changes between Development and Production, and how to keep passwords and API keys out of source control with user secrets.
- Logging and Diagnostics Use ILogger in ASP.NET Core: log levels, categories and filters, structured message templates, scopes, LoggerMessage and simple request logging.
Models, Validation and Serialization
- JSON Serialization in APIs Control JSON in ASP.NET Core APIs: web defaults, naming policies, enums, custom converters, polymorphism and the shared JsonSerializerOptions.
- Model Validation Validate API input in ASP.NET Core with data annotations, IValidatableObject, custom attributes, endpoint filters and the .NET 10 minimal API validation.
- DTOs, Records and Mapping Why APIs should not expose entities: use record DTOs, write simple mapping methods, project queries, and evolve response shapes without breaking clients.
MVC, Controllers and Razor
- Controllers and Actions Build web APIs with controllers: ControllerBase, [ApiController], attribute routing, action results, ActionResult<T>, dependency injection and conventions.
- Model Binding and Filters in MVC How MVC binds request data to action parameters, how ModelState and the automatic 400 work, and how action, exception and result filters run in order.
- Razor Views and Razor Pages Overview Learn Razor syntax, automatic HTML encoding, layouts, partials, tag helpers, view components and Razor Pages handlers, with runnable stand-ins you can edit.
- Blazor Overview Understand Blazor components, the four render modes (static SSR, Interactive Server, WebAssembly, Auto), forms and streaming rendering, and when to choose Blazor.
Data Access
- Data Access without an ORM Learn ADO.NET basics, parameterized queries, the repository pattern, an in-memory ConcurrentDictionary store, Dapper-style row mapping and async data access.
- Entity Framework Core Overview Learn what Entity Framework Core does: DbContext, entities, LINQ queries, change tracking, SaveChanges, relationships and migrations, with runnable stand-ins.
- EF Core in Practice Use EF Core well in web apps: AsNoTracking, fixing N+1 with Include, keyset pagination, concurrency tokens, transactions and DbContext lifetime.
- Caching: Memory, Distributed and Output Speed up ASP.NET Core with IMemoryCache, expiration policies, stampede protection, IDistributedCache, HTTP caching headers with ETags and output caching.
Authentication and Authorization
- Authentication Concepts Understand ASP.NET Core authentication: schemes, handlers, claims and ClaimsPrincipal, challenge versus forbid, and build a custom API key handler.
- Cookie and JWT Bearer Authentication Learn how cookie authentication and JWT bearer tokens work in ASP.NET Core, and build and validate an HMAC-signed token by hand to see what happens inside.
- Authorization: Roles, Policies and Handlers Learn ASP.NET Core authorization: roles, claim-based policies, custom requirements and handlers, resource-based checks and a fallback policy, with live examples.
- ASP.NET Core Identity Overview A tour of ASP.NET Core Identity: users and roles, password hashing, lockout, two-factor authentication, passkeys and external logins, with runnable stand-ins.
- Web Security Essentials The web security basics every ASP.NET Core developer needs: HTTPS and HSTS, security headers, XSS encoding, antiforgery tokens, injection, data protection and open redirects.
Advanced Topics
- Background Services and Hosted Services Run work outside requests with IHostedService and BackgroundService: timers, Channel<T> queues, scoped services in singletons and graceful shutdown.
- Calling Other Services: HttpClient and Resilience Call other services from ASP.NET Core with IHttpClientFactory and typed clients, then add timeouts, retries and a circuit breaker with delegating handlers.
- Real-time: WebSockets and Server-Sent Events Push data to browsers in real time with ASP.NET Core: build a WebSocket echo server, stream Server-Sent Events with TypedResults, and learn when to use SignalR.
- OpenAPI, Documentation and API Versioning Document ASP.NET Core APIs with OpenAPI endpoint metadata, pick a versioning strategy, and apply pagination and idempotency-key conventions with runnable code.
- Rate Limiting, Health Checks and Resilience of the App Protect an ASP.NET Core app with rate limiter policies, request timeouts and health check endpoints for liveness and readiness, with runnable examples.
Testing, Performance and Deployment
- Testing ASP.NET Core Apps Test ASP.NET Core apps with confidence: unit-test handlers and middleware, build an in-process integration test factory, swap in fakes and pin the clock.
- Performance Tuning Make ASP.NET Core apps faster: async all the way, response compression, output caching, fewer allocations, pooling, Native AOT and how to measure it all.
- Deployment: Kestrel, Reverse Proxies and Containers Ship an ASP.NET Core app: configure Kestrel, trust a reverse proxy with forwarded headers, choose publish options and build a small Docker image.
- Observability in Production See inside a running ASP.NET Core app: custom metrics with Meter, distributed traces with ActivitySource, structured logs and correlation, with OpenTelemetry.
Projects
- Project: Todo API Build a complete Todo API with minimal APIs: CRUD endpoints, validation, problem details, typed results and an in-memory store, tested end to end.
- Project: URL Shortener Build a URL shortener in ASP.NET Core: base62 ids, safe redirects, custom aliases, per-client rate limiting, memory caching and click counting.
- Project: Notes API with Authentication Build a Notes API in ASP.NET Core with API key authentication, a fallback policy, role policies and per-user resource authorization that stops IDOR bugs.
- Project: Real-time Chat with SSE and WebSockets Build a multi-room chat in ASP.NET Core: broadcast with Channel<T>, a Server-Sent Events stream with resume, and a two-way WebSocket endpoint.
- Project: Blog API with Pagination and Caching Build a layered blog API in ASP.NET Core: filtering, paging, ETags with conditional requests, output caching with tag eviction, and a tiny in-process test suite.
Practice and Review
- Practice Exercises with Solutions Twelve graded ASP.NET Core exercises on routing, middleware, dependency injection and authorization, each with a full, runnable solution you can check.
- ASP.NET Core Interview Questions Forty ASP.NET Core interview questions with concise answers: pipeline, middleware, routing, dependency injection, auth, caching, performance and deployment.
- ASP.NET Core Cheat Sheet A one-page ASP.NET Core 10 cheat sheet: builder, routing, binding, results, middleware order, DI lifetimes, auth, configuration and deployment commands.