ASP.NET Core is the part of .NET you use to build a web application or an HTTP API. It is a request pipeline, a dependency injection container and a hosting model, and almost everything else is a library you plug into those three.
The sections below run roughly in the order the problems arrive: getting a response out of a controller, binding what came in, documenting it, calling somebody else’s API, then the pipeline, caching, configuration and how the thing runs in production.
A note on the two hosting styles. Controllers and minimal APIs are not competing religions. Controllers give you a class per resource and a lot of convention; minimal APIs give you a delegate and almost none. Both are in here, usually in the same section, because the underlying question is normally the same one.
If you are starting from nothing, the Web API tutorial series at the top builds a complete application over several parts. Everything after it answers one question at a time.
The Web API Tutorial Series
One application, built up part by part, so the shape of a Web API arrives before the details do.
- ASP.NET Core Web API – Repository Pattern
- ASP.NET Core Web API – Post, Put, Delete
- ASP.NET Core Web API – How to Handle Get Request
- ASP.NET Core Web API – .NET Service Configuration
- ASP.NET Core Web API – Logging With NLog
Web API Design and Best Practices
What a good API looks like before any of it is code. Worth twenty minutes at the start of a project and nearly useless at the end.
- ASP.NET Core Web API Best Practices
- Asynchronous Programming with Async and Await
- 10 Things You Should Avoid in Your ASP.NET Core Controllers
- Top REST API Best Practices
- The Difference Between RESTful APIs and Web APIs Using ASP.NET Core
MVC, Razor and Views
Server-rendered pages: views, layouts, tag helpers and the bits of MVC that have no equivalent in a Web API.
- Views, Partial Views, and Layouts in ASP.NET Core MVC
- File Upload in ASP.NET Core MVC
- Routing in ASP.NET Core MVC
- State Management in ASP.NET Core MVC
- Filters in ASP.NET Core MVC
- Dynamically Adding Rows on a Form in Razor Pages
- Dependency Injection in ASP.NET Core MVC
- Different Ways to Use Select Tag Helper
- How to Implement Checkbox List
- Getting Started with ASP.NET Core MVC
- Working with Data in ASP.NET Core MVC
Swagger and API Documentation
Swagger is the first thing most teams turn on and the first thing that starts showing more than it should.
- Configuring and Using Swagger UI in ASP.NET Core Web API
- Swashbuckle vs. NSwag
- The AddEndpointsApiExplorer Method
- How to Hide an Endpoint in Swagger
- How to Ignore Model Properties With Swagger
- How to Modify a Base URI of Swagger
- How to Show Query Parameters in Swagger
- Adding a Custom Header Parameter to All API Endpoints in Swagger
Real-Time: SignalR, WebSockets and Server-Sent Events
Three ways to push rather than wait to be asked, and the reasons to pick one over another.
- REST vs WebSockets
- How to Call SignalR Hub from Controller
- How to Send Client-Specific Messages Using SignalR
- Using Server-Sent Events for Realtime Updates
Consuming APIs With HttpClient
Calling somebody else’s API is where most of the sharp edges are: lifetimes, timeouts, headers, cancellation and the socket exhaustion that follows from getting the first one wrong.
- Multipart Form-Data in HttpClient with ASP.NET Core
- A Few Great Ways to Consume RESTful API
- POST, PUT, and DELETE Requests Using HttpClient
- Canceling HTTP Requests in ASP.NET Core with CancellationToken
- Google Sheets API with .NET Core
- Fetching Data and Content Negotiation with HttpClient
- Change Default and per Request Timeout in HttpClient
- Add a Cookie to an HttpClient Request/Response
- Using Streams with HttpClient to Improve Performance and Memory Usage
- How to Send a JSON Object Using HttpClient
- How to Set a Default User-Agent on an HttpClient
- Using HttpClient to Send HTTP PATCH Requests
- How to Add a BearerToken to an HttpClient Request
- Using HttpClientFactory in ASP.NET Core Applications
- How to Set an Authenticator for a New RestClient in RestSharp
- How to Find the Latitude and Longitude of a Location
- Using Delegating Handlers to Extend HttpClient
- Using Refit to Consume APIs
- Using C# and DalSoft.RestClient to Consume Any REST API
Returning Data From a Web API
What actually goes back down the wire, and how to say “this went wrong” in a way the caller can act on.
- Web API Return Types
- Content Negotiation in Web API
- Implementing HATEOAS in ASP.NET Core Web API
- Data Shaping in ASP.NET Core Web API
- Content Negotiation in an ASP.NET Core Minimal API Using Carter
- How to Return HTTP 500 From ASP.NET Core Web API
- Return File in ASP.NET Core Web API
- How to Return HTML From ASP.NET Core Web API
- Using the ProblemDetails Class in ASP.NET Core Web API
- How to Return XML From ASP.NET Core Web API
- Using the Result Pattern in .NET Web API
- How to Use the REPR (Request-Endpoint-Response) Pattern
- Creating Multiple Resources with a Single Request
File Uploads and Transfer
Accepting a file is easy. Accepting it safely, at size, and rejecting the ones you should is the part these cover.
- Uploading Large Files
- How to Validate File Upload Extensions
- How to Use SFTP For Secure File Upload
- Different Ways to Validate an Uploaded File
Model Binding, Validation and Request Data
Everything between the request arriving and your method running.
- Optional Parameters in Web API Routing
- StringValues
- Required Query String Parameters
- How To Read the Request Body in ASP.NET Core Web API
- How to Use ModelState Validation in ASP.NET Core Web API
- How to Pass Parameters With a GET Request
- How to Extract Custom Header in ASP.NET Core Web API
- How to Call an Action From Another Controller
- Using HttpContext.Items to Pass Data With ASP.NET Core
- Creating Conditional Required Attributes for Validation in .NET Web API
- Using Query String Parameters with Minimal APIs
- How to Get the Remote Host IP Address in ASP.NET Core Web API
- How to Add Custom Headers in ASP.NET Core Web API
- How to Read Values From Query Strings
- How to Add Multiple POST Actions in ASP.NET Core Web API
Routing, Controllers and Minimal APIs
How a URL finds your code, in both hosting styles.
- MapControllers vs MapControllerRoute
- ApiController Attribute in ASP.NET Core Web API
- API Versioning
- Better Minimal APIs Endpoint Organization With Carter
- Minimal APIs in .NET 6
- Automatic Registration of Minimal API Endpoints
- How to Add a Global Route Prefix
- Using OData with ASP.NET Core Web API
- How to Build a URL Shortener in .NET Applications
JSON and Serialization
The serializer settings that bite once and then never again, usually after an afternoon.
- How to Set Global Default JSON Serialization Options
- Handling Circular References When Working With JSON
- How to Get appsettings.json Content as a Dictionary
Middleware, Filters and the Pipeline
The pipeline is the part of ASP.NET Core that rewards being understood properly, because almost every cross-cutting concern belongs in it.
- Present a List of Files in a Directory With Directory Browsing
- HSTS Header Implementation
- Implementing Action Filters
- ASP.NET Core Middleware – Creating Flexible Application Flows
- Global Error Handling in ASP.NET Core Web API
- Localization
- Conditionally Add Middleware
- Web API Analyzers
- Content Security Policy
- How to Use Request Timeouts Middleware
- How to Implement Audit Trail in ASP.NET Core Web API
- How to Block IP Addresses in ASP.NET Core Web API
Caching, Rate Limiting and Performance
Doing less work, and refusing work you do not want.
- Built-In Rate Limiting in ASP.NET Core Web API
- Distributed Caching
- Hybrid Caching
- In-Memory Caching
- Response Caching
- Output Caching
- Rate Limiting in ASP.NET Core Web API (.NET 6)
- Optimistic Concurrency in ASP.NET Core Web API
- Getting Started With EasyCaching
Paging, Filtering, Searching and Sorting
The four things every list endpoint grows, in roughly this order and about one release apart.
- Paging in ASP.NET Core Web API
- Searching in ASP.NET Core Web API
- Filtering in ASP.NET Core Web API
- How to Implement Sorting in ASP.NET Core Web API
Generating Files and Documents
Producing something the caller downloads rather than reads.
- Generate QR Codes With QRCoder
- How to Easily Create a PDF Document in ASP.NET Core Web API
- Generate Images Using OpenAI in an ASP.NET Core Application
Configuration, Options and Environments
Where settings come from, how to validate them, and how to keep the ones that matter out of source control.
- Tools and Best Practices for Secret Management
- Multiple Environments
- Feature Flags
- ASP.NET Core Configuration – Configuration Providers
- ASP.NET Core Configuration – Options Pattern
- ASP.NET Core Configuration – Basic Concepts
- Securing Sensitive Data Locally
- ASP.NET Core Configuration – Options Validation
- How to Get a JSON Array Using IConfiguration
- How to Mock IConfiguration.GetValue
- How to Read AppSettings Values From a JSON File in .NET Core
- Creating Custom Configuration Provider
- How to Register Services for Different Environments
- Using Source Generators to Validate IOptions
Dependency Injection
The container is built in, so the questions are about lifetime and registration rather than about which library to pick.
- What Is Service Discovery in .NET and How to Use It?
- Dependency Injection
- Dependency Injection Lifetimes
- How to Register Multiple Implementations of the Same Interface
- How to Resolve Instances With ASP.NET Core DI
Background Work and Hosting
Work that outlives a request, and the ways an ASP.NET Core process actually gets hosted.
- Running .NET Core Applications as a Windows Service
- InProcess and OutOfProcess Hosting Models
- Running .NET Core Applications as a Linux Service
- Manage Background Tasks With The IHostedLifecycleService Interface
- Hot Reload in ASP.NET Core Applications
- Dockerizing ASP.NET Core Application With Dockerfiles
- Long-Running Tasks in a Monolith ASP.NET Core Application
- How to Solve the HTTP Error 500.31 – Failed to Load ASP.NET Core Runtime Error
- Different Ways to Run Background Tasks
- How to Send an Email
- How to Send Emails With the SendGrid API
- How to Send an SMS with ASP.NET Core
- How to Prepare an ASP.NET Core Application for Dockerization
Architecture
Shapes for a whole application. These are the hardest to change later, so the articles spend time on when not to.
- Onion Architecture
- Implementing Asynchronous Generic Repository
- Vertical Slice Architecture
- Implementing API Gateway with Ocelot
- How to Build a Multitenant Application with ASP.NET Core
More ASP.NET Core
The rest, filed where it did not fit anywhere above.
Where to Go Next
The two things an ASP.NET Core application almost always needs next:
- Entity Framework Core
- Identity, Authentication and Security
- ASP.NET Core MVC
- Testing ASP.NET Core Applications
When something behaves oddly, work out where in the request it happens before you go looking for the feature that owns it. A surprising number of ASP.NET Core problems turn out to be about pipeline order.
