concept middleware pipeline in category asp.net

appears as: middleware pipeline, middleware pipeline, The middleware pipeline, middleware pipelines
ASP.NET Core in Action, Second Edition MEAP V04

This is an excerpt from Manning's book ASP.NET Core in Action, Second Edition MEAP V04.

Figure 2.9 shows the typical split of configuration components between Program and Startup. Generally speaking, Program is where you configure the infrastructure of your application, such as the HTTP server, integration with IIS, and configuration sources. In contrast, Startup is where you define which components and features your application uses, and the middleware pipeline for your app.

The middleware pipeline is one of the most important parts of configuration for defining how your application behaves and how it responds to requests. Understanding how to build and compose middleware is key to adding functionality to your applications.

Figure 3.1 Example of a middleware pipeline. Each middleware handles the request and passes it on to the next middleware in the pipeline. After a middleware generates a response, it passes it back through the pipeline. When it reaches the ASP.NET Core web server, the response is sent to the user’s browser.
A close up of a logo Description automatically generated
Figure 3.4 WelcomePageMiddleware
handles a request. The request passes from the reverse proxy to the ASP.NET Core web server and, finally, to the middleware pipeline, which generates an HTML response.

The request passes to the ASP.NET Core web server, which builds a representation of the request and passes it to the middleware pipeline. As it’s the first (only!) middleware in the pipeline, WelcomePageMiddleware receives the request and must decide how to handle it. The middleware responds by generating an HTML response, no matter what request it receives. This response passes back to the ASP.NET Core web server, which forwards it on to the user to display in their browser.

As with all ASP.NET Core applications, you define the middleware pipeline in the Configure method of Startup by adding middleware to an IApplicationBuilder object. To create your first middleware pipeline, consisting of a single middleware component, you need just a single method call.

ASP.NET Core in Action

This is an excerpt from Manning's book ASP.NET Core in Action.

Figure 2.1. An overview of an ASP.NET Core application. The ASP.NET Core application contains a number of blocks that process an incoming request from the browser. Every request passes to the middleware pipeline. It potentially modifies it, then passes it to the MVC middleware at the end of the pipeline to generate a response. The response passes back through the middleware, to the server, and finally, out to the browser.
Listing 2.3. An outline of Startup.cs showing how each aspect is configured

And there you have it, a complete ASP.NET Core MVC application! Before I move on, we’ll take one last look at how our application handles a request. Figure 2.17 shows a request to the /Home/About path being handled by the sample application. You’ve seen everything here already, so the process of handling a request should be familiar. It shows how the request passes through the middleware pipeline before being handled by the MVC middleware. A view is used to generate the HTML response, which passes back through the middleware to the ASP.NET Core web server, before being sent to the user’s browser.

Figure 2.17. An overview of a request to the /Home/About page for the sample ASP.NET Core application. The request is received by the reverse proxy and passed to the ASP.NET Core web server. It then passes through the middleware pipeline unchanged, until it’s handled by the MVC middleware. The MVC middleware generates an HTML response by executing a view template. The response passes back through the middleware, to the server, and finally, out to the browser.

It’s been a pretty intense trip, but you now have a good overview of how an entire application is configured and how it handles a request using MVC. In the next chapter, you’ll take a closer look at the middleware pipeline that exists in all ASP.NET Core applications. You’ll learn how it’s composed, how you can use it to add functionality to your application, and how you can use it to create simple HTTP services.

The middleware pipeline is one of the most important parts of configuration for defining how your application behaves and how it responds to requests. Understanding how to build and compose middleware is key to adding functionality to your applications.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest