When you’re building apps with ASP.NET Core, most of your creativity and specialization goes into the services and models that make up your business logic and the Razor Pages and controllers that expose them through views or APIs. Eventually, however, you’re likely to find that you can’t quite achieve a desired feature using the components that come out of the box. At that point, you may need to build a custom component.
This chapter shows how you can create some ASP.NET Core components that you’re likely to need as your app grows. You probably won’t need to use all of them, but each solves a specific problem you may run into.
We’ll start by looking at the middleware pipeline. You saw how to build pipelines by piecing together existing middleware in chapter 3, but in this chapter you’ll create your own custom middleware. You’ll explore the basic middleware constructs of the Map
, Use
, and Run
methods and learn how to create standalone middleware classes. You’ll use these to build middleware components that can add headers to all your responses as well as middleware that returns responses.