Middleware



Transactional Middleware means the tech that reinforces the working of electronic transactions in a branched background. The best example is Transaction Processing Monitors (TPM), which have been in the market for more than 30 years. Robotic Middleware. Robotics middleware is the middleware used in building extensive robot control software systems. You've seen middleware in action in the 'Redux Fundamentals' tutorial.If you've used server-side libraries like Express and Koa, you were also probably already familiar with the concept of middleware.In these frameworks, middleware is some code you can put between the framework receiving a request, and the framework generating a response.

  1. Middleware appears in many locations; however, organizations and developers make specific use of middleware to more efficiently build applications. Organizations that use multi-cloud and containerized environments will often also use middleware as a more cost-effective way to develop and scale applications.
  2. Middleware is a computer software that provides services to software applications beyond those available from the operating system. It can be described as 'software glue'. Middleware makes it easier for software developers to implement communication and input/output, so they can focus on the.
  3. Middleware enables the DoD PKI certificates stored on your Common Access Card (CAC) to interface with the many Public Key Enabled (PKE) applications on your system and across the Internet. Two of the most common middleware applications used across DoD are ActivClient and Spyrus.

Middleware is a type of computer software that provides services to software applications beyond those available from the operating system. It can be described as 'software glue'.[1]

Middleware makes it easier for software developers to implement communication and input/output, so they can focus on the specific purpose of their application. It gained popularity in the 1980s as a solution to the problem of how to link newer applications to older legacy systems, although the term had been in use since 1968.[2]

In distributed applications[edit]

Software architecture: Middleware

The term is most commonly used for software that enables communication and management of data in distributed applications. An IETF workshop in 2000 defined middleware as 'those services found above the transport (i.e. over TCP/IP) layer set of services but below the application environment' (i.e. below application-level APIs).[3] In this more specific sense middleware can be described as the dash ('-') in client-server, or the -to- in peer-to-peer. Middleware includes web servers, application servers, content management systems, and similar tools that support application development and delivery.[4]

ObjectWeb defines middleware as: 'The software layer that lies between the operating system and applications on each side of a distributed computing system in a network.'[5] Services that can be regarded as middleware include enterprise application integration, data integration, message oriented middleware (MOM), object request brokers (ORBs), and the enterprise service bus (ESB).[6]

Database access services are often characterised as middleware. Some of them are language specific implementations and support heterogeneous features and other related communication features.[7] Examples of database-oriented middleware include ODBC, JDBC and transaction processing monitors.[8]

Distributed computing system middleware can loosely be divided into two categories—those that provide human-time services (such as web request servicing) and those that perform in machine-time. This latter middleware is somewhat standardized through the Service Availability Forum[9] and is commonly used in complex, embedded systems within telecom, defence and aerospace industries.[10]

Other examples[edit]

The term middleware is used in other contexts as well. Middleware is sometimes used in a similar sense to a software driver, an abstraction layer that hides detail about hardware devices or other software from an application.

  • The Android operating system uses the Linux kernel at its core, and also provides an application framework that developers incorporate into their applications. In addition, Android provides a middleware layer including libraries that provide services such as data storage, screen display, multimedia, and web browsing. Because the middleware libraries are compiled to machine language, services execute quickly. Middleware libraries also implement device-specific functions, so applications and the application framework need not concern themselves with variations between various Android devices. Android's middleware layer also contains the ARTvirtual machine and its core Java application libraries.[11]
  • Middleware also refers to the software that separates two or more APIs and provides services such as rate-limiting, authentication, and logging.
  • Game engine software such as Gamebryo and RenderWare are sometimes described as middleware, because they provide many services to simplify game development.[12]
  • In simulation technology, middleware is generally used in the context of the high level architecture (HLA) that applies to many distributed simulations. It is a layer of software that lies between the application code and the run-time infrastructure. Middleware generally consists of a library of functions, and enables a number of applications—simulations or federates in HLA terminology—to page these functions from the common library rather than re-create them for each application.[13]
  • Wireless networking developers can use middleware to meet the challenges associated with a wireless sensor network (WSN). Implementing a middleware application allows WSN developers to integrate operating systems and hardware with the wide variety of various applications that are currently available.[14]
  • The QNX operating system offers middleware for providing multimedia services for use in automobiles, aircraft and other environments.[15]
  • Radio-frequency identification (RFID) software toolkits provide middleware to filter noisy and redundant raw data.[16]

See also[edit]

References[edit]

  1. ^'What is Middleware?'. Middleware.org. Defining Technology. 2008. Archived from the original on June 29, 2012. Retrieved 2013-08-11.CS1 maint: unfit URL (link)
  2. ^Gall, Nick (July 30, 2005). 'Origin of the term middleware'.
  3. ^'Home'. IETF.
  4. ^Etzkorn, L. H. (2017). Introduction to Middleware: Web Services, Object Components, and Cloud Computing. CRC Press. pp. 4–5. ISBN9781498754101.
  5. ^Krakowiak, Sacha. 'What's middleware?'. ObjectWeb.org. Archived from the original on 2005-05-07. Retrieved 2005-05-06.
  6. ^Luckham, D. C. (2011). Event Processing for Business: Organizing the Real-Time Enterprise. John Wiley & Sons. pp. 27–28. ISBN9781118171851.
  7. ^Simon, A. R.; Wheeler, T. (2014). Open Client/Server Computing and Middleware. Academic Press. pp. 43–49. ISBN9781483214276.
  8. ^Arregoces, M.; Portolani, M. (2003). Data Center Fundamentals. Cisco Press. pp. 92–93. ISBN9781587140747.
  9. ^'Service Availability Interface Specification'(PDF). Service Availability Forum. 30 September 2011. Retrieved 26 July 2018.
  10. ^Jokiaho, T.; Fryer, J. (2012). 'Foreword'. Service Availability: Principles and Practice. John Wiley & Sons. p. xv. ISBN9781119941675.
  11. ^Charlie Collins, Michael Galpin and Matthias Kaeppler, Android in Practice, Manning Publications, 2011
  12. ^Moore, M. E. (2006). Introduction to the Game Industry. Pearson Prentice Hall. p. 169. ISBN9780131687431.
  13. ^Becchini, R.; Chilaev, P.; Krivtsov, V.; et al. (2003). 'Chapter 4: Middleware'. In Drira, K.; Martelli, A.; Villemur, T. (eds.). Cooperative Environments for Distributed Systems Engineering: The Distributed Systems Environment Report. Springer. pp. 41–4. ISBN9783540455820.
  14. ^Hadim, S. and Mohamed, N. (2006). Middleware challenges and approaches for wireless sensor networks. IEEE Distributed Systems Online vol 7. Issue 3. Retrieved March 4, 2009 fromiEEE Distributed Systems OnlineArchived 2011-09-28 at the Wayback Machine
  15. ^'QNX Software Joins Internet ITS Consortium of Japan'. QNX News Releases. QNX. 6 May 2008. Retrieved 26 July 2018.
  16. ^Glover, B.; Bhatt, H. (2006). RFID Essentials. O'Reilly Media. pp. 38–44. ISBN9780596009441.

External links[edit]

  • The dictionary definition of middleware at Wiktionary
Retrieved from 'https://en.wikipedia.org/w/index.php?title=Middleware&oldid=1019034461'
-->

Middleware Cac Army

By Rick Anderson and Steve Smith

Middleware is software that's assembled into an app pipeline to handle requests and responses. Each component:

  • Chooses whether to pass the request to the next component in the pipeline.
  • Can perform work before and after the next component in the pipeline.

Request delegates are used to build the request pipeline. The request delegates handle each HTTP request.

Request delegates are configured using Run, Map, and Use extension methods. An individual request delegate can be specified in-line as an anonymous method (called in-line middleware), or it can be defined in a reusable class. These reusable classes and in-line anonymous methods are middleware, also called middleware components. Each middleware component in the request pipeline is responsible for invoking the next component in the pipeline or short-circuiting the pipeline. When a middleware short-circuits, it's called a terminal middleware because it prevents further middleware from processing the request.

Migrate HTTP handlers and modules to ASP.NET Core middleware explains the difference between request pipelines in ASP.NET Core and ASP.NET 4.x and provides additional middleware samples.

Create a middleware pipeline with IApplicationBuilder

The ASP.NET Core request pipeline consists of a sequence of request delegates, called one after the other. The following diagram demonstrates the concept. The thread of execution follows the black arrows.

Middleware

Each delegate can perform operations before and after the next delegate. Exception-handling delegates should be called early in the pipeline, so they can catch exceptions that occur in later stages of the pipeline.

The simplest possible ASP.NET Core app sets up a single request delegate that handles all requests. This case doesn't include an actual request pipeline. Instead, a single anonymous function is called in response to every HTTP request.

Chain multiple request delegates together with Use. The next parameter represents the next delegate in the pipeline. You can short-circuit the pipeline by not calling the next parameter. You can typically perform actions both before and after the next delegate, as the following example demonstrates:

When a delegate doesn't pass a request to the next delegate, it's called short-circuiting the request pipeline. Short-circuiting is often desirable because it avoids unnecessary work. For example, Static File Middleware can act as a terminal middleware by processing a request for a static file and short-circuiting the rest of the pipeline. Middleware added to the pipeline before the middleware that terminates further processing still processes code after their next.Invoke statements. However, see the following warning about attempting to write to a response that has already been sent.

Warning

Don't call next.Invoke after the response has been sent to the client. Changes to HttpResponse after the response has started throw an exception. For example, setting headers and a status code throw an exception. Writing to the response body after calling next:

  • May cause a protocol violation. For example, writing more than the stated Content-Length.
  • May corrupt the body format. For example, writing an HTML footer to a CSS file.

HasStarted is a useful hint to indicate if headers have been sent or the body has been written to.

Run delegates don't receive a next parameter. The first Run delegate is always terminal and terminates the pipeline. Run is a convention. Some middleware components may expose Run[Middleware] methods that run at the end of the pipeline:

If you would like to see code comments translated to languages other than English, let us know in this GitHub discussion issue.

Middleware architecture

In the preceding example, the Run delegate writes 'Hello from 2nd delegate.' to the response and then terminates the pipeline. If another Use or Run delegate is added after the Run delegate, it's not called.

Middleware order

The following diagram shows the complete request processing pipeline for ASP.NET Core MVC and Razor Pages apps. You can see how, in a typical app, existing middlewares are ordered and where custom middlewares are added. You have full control over how to reorder existing middlewares or inject new custom middlewares as necessary for your scenarios.

The Endpoint middleware in the preceding diagram executes the filter pipeline for the corresponding app type—MVC or Razor Pages.

The order that middleware components are added in the Startup.Configure method defines the order in which the middleware components are invoked on requests and the reverse order for the response. The order is critical for security, performance, and functionality.

Middleware Applications

The following Startup.Configure method adds security-related middleware components in the typical recommended order:

In the preceding code:

  • Middleware that is not added when creating a new web app with individual users accounts is commented out.
  • Not every middleware needs to go in this exact order, but many do. For example:
    • UseCors, UseAuthentication, and UseAuthorization must go in the order shown.
    • UseCors currently must go before UseResponseCaching due to this bug.

In some scenarios, middleware will have different ordering. For example, caching and compression ordering is scenario specific, and there's multiple valid orderings. For example:

With the preceding code, CPU could be saved by caching the compressed response, but you might end up caching multiple representations of a resource using different compression algorithms such as gzip or brotli.

The following ordering combines static files to allow caching compressed static files:

Middleware Products List

The following Startup.Configure method adds middleware components for common app scenarios:

  1. Exception/error handling
    • When the app runs in the Development environment:
      • Developer Exception Page Middleware (UseDeveloperExceptionPage) reports app runtime errors.
      • Database Error Page Middleware reports database runtime errors.
    • When the app runs in the Production environment:
      • Exception Handler Middleware (UseExceptionHandler) catches exceptions thrown in the following middlewares.
      • HTTP Strict Transport Security Protocol (HSTS) Middleware (UseHsts) adds the Strict-Transport-Security header.
  2. HTTPS Redirection Middleware (UseHttpsRedirection) redirects HTTP requests to HTTPS.
  3. Static File Middleware (UseStaticFiles) returns static files and short-circuits further request processing.
  4. Cookie Policy Middleware (UseCookiePolicy) conforms the app to the EU General Data Protection Regulation (GDPR) regulations.
  5. Routing Middleware (UseRouting) to route requests.
  6. Authentication Middleware (UseAuthentication) attempts to authenticate the user before they're allowed access to secure resources.
  7. Authorization Middleware (UseAuthorization) authorizes a user to access secure resources.
  8. Session Middleware (UseSession) establishes and maintains session state. If the app uses session state, call Session Middleware after Cookie Policy Middleware and before MVC Middleware.
  9. Endpoint Routing Middleware (UseEndpoints with MapRazorPages) to add Razor Pages endpoints to the request pipeline.

In the preceding example code, each middleware extension method is exposed on IApplicationBuilder through the Microsoft.AspNetCore.Builder namespace.

UseExceptionHandler is the first middleware component added to the pipeline. Therefore, the Exception Handler Middleware catches any exceptions that occur in later calls.

Static File Middleware is called early in the pipeline so that it can handle requests and short-circuit without going through the remaining components. The Static File Middleware provides no authorization checks. Any files served by Static File Middleware, including those under wwwroot, are publicly available. For an approach to secure static files, see Static files in ASP.NET Core.

If the request isn't handled by the Static File Middleware, it's passed on to the Authentication Middleware (UseAuthentication), which performs authentication. Authentication doesn't short-circuit unauthenticated requests. Although Authentication Middleware authenticates requests, authorization (and rejection) occurs only after MVC selects a specific Razor Page or MVC controller and action.

The following example demonstrates a middleware order where requests for static files are handled by Static File Middleware before Response Compression Middleware. Static files aren't compressed with this middleware order. The Razor Pages responses can be compressed.

For Single Page Applications (SPAs), the SPA middleware UseSpaStaticFiles usually comes last in the middleware pipeline. The SPA middleware comes last:

  • To allow all other middlewares to respond to matching requests first.
  • To allow SPAs with client-side routing to run for all routes that are unrecognized by the server app.
Middleware

For more details on SPAs, see the guides for the React and Angular project templates.

Forwarded Headers Middleware order

Forwarded Headers Middleware should run before other middleware. This ordering ensures that the middleware relying on forwarded headers information can consume the header values for processing. To run Forwarded Headers Middleware after diagnostics and error handling middleware, see Forwarded Headers Middleware order.

Branch the middleware pipeline

Map extensions are used as a convention for branching the pipeline. Map branches the request pipeline based on matches of the given request path. If the request path starts with the given path, the branch is executed.

The following table shows the requests and responses from http://localhost:1234 using the previous code.

RequestResponse
localhost:1234Hello from non-Map delegate.
localhost:1234/map1Map Test 1
localhost:1234/map2Map Test 2
localhost:1234/map3Hello from non-Map delegate.
Middleware meaning

When Map is used, the matched path segments are removed from HttpRequest.Path and appended to HttpRequest.PathBase for each request.

Map supports nesting, for example:

Map can also match multiple segments at once:

MapWhen branches the request pipeline based on the result of the given predicate. Any predicate of type Func<HttpContext, bool> can be used to map requests to a new branch of the pipeline. In the following example, a predicate is used to detect the presence of a query string variable branch:

The following table shows the requests and responses from http://localhost:1234 using the previous code:

RequestResponse
localhost:1234Hello from non-Map delegate.
localhost:1234/?branch=mainBranch used = main

UseWhen also branches the request pipeline based on the result of the given predicate. Unlike with MapWhen, this branch is rejoined to the main pipeline if it doesn't short-circuit or contain a terminal middleware:

In the preceding example, a response of 'Hello from main pipeline.' is written for all requests. If the request includes a query string variable branch, its value is logged before the main pipeline is rejoined.

Built-in middleware

ASP.NET Core ships with the following middleware components. The Order column provides notes on middleware placement in the request processing pipeline and under what conditions the middleware may terminate request processing. When a middleware short-circuits the request processing pipeline and prevents further downstream middleware from processing a request, it's called a terminal middleware. For more information on short-circuiting, see the Create a middleware pipeline with IApplicationBuilder section.

MiddlewareDescriptionOrder
AuthenticationProvides authentication support.Before HttpContext.User is needed. Terminal for OAuth callbacks.
AuthorizationProvides authorization support.Immediately after the Authentication Middleware.
Cookie PolicyTracks consent from users for storing personal information and enforces minimum standards for cookie fields, such as secure and SameSite.Before middleware that issues cookies. Examples: Authentication, Session, MVC (TempData).
CORSConfigures Cross-Origin Resource Sharing.Before components that use CORS. UseCors currently must go before UseResponseCaching due to this bug.
DiagnosticsSeveral separate middlewares that provide a developer exception page, exception handling, status code pages, and the default web page for new apps.Before components that generate errors. Terminal for exceptions or serving the default web page for new apps.
Forwarded HeadersForwards proxied headers onto the current request.Before components that consume the updated fields. Examples: scheme, host, client IP, method.
Health CheckChecks the health of an ASP.NET Core app and its dependencies, such as checking database availability.Terminal if a request matches a health check endpoint.
Header PropagationPropagates HTTP headers from the incoming request to the outgoing HTTP Client requests.
HTTP Method OverrideAllows an incoming POST request to override the method.Before components that consume the updated method.
HTTPS RedirectionRedirect all HTTP requests to HTTPS.Before components that consume the URL.
HTTP Strict Transport Security (HSTS)Security enhancement middleware that adds a special response header.Before responses are sent and after components that modify requests. Examples: Forwarded Headers, URL Rewriting.
MVCProcesses requests with MVC/Razor Pages.Terminal if a request matches a route.
OWINInterop with OWIN-based apps, servers, and middleware.Terminal if the OWIN Middleware fully processes the request.
Response CachingProvides support for caching responses.Before components that require caching. UseCORS must come before UseResponseCaching.
Response CompressionProvides support for compressing responses.Before components that require compression.
Request LocalizationProvides localization support.Before localization sensitive components.
Endpoint RoutingDefines and constrains request routes.Terminal for matching routes.
SPAHandles all requests from this point in the middleware chain by returning the default page for the Single Page Application (SPA)Late in the chain, so that other middleware for serving static files, MVC actions, etc., takes precedence.
SessionProvides support for managing user sessions.Before components that require Session.
Static FilesProvides support for serving static files and directory browsing.Terminal if a request matches a file.
URL RewriteProvides support for rewriting URLs and redirecting requests.Before components that consume the URL.
WebSocketsEnables the WebSockets protocol.Before components that are required to accept WebSocket requests.

Additional resources

  • Lifetime and registration options contains a complete sample of middleware with scoped, transient, and singleton lifetime services.

By Rick Anderson and Steve Smith

Middleware is software that's assembled into an app pipeline to handle requests and responses. Each component:

  • Chooses whether to pass the request to the next component in the pipeline.
  • Can perform work before and after the next component in the pipeline.

Request delegates are used to build the request pipeline. The request delegates handle each HTTP request.

Request delegates are configured using Run, Map, and Use extension methods. An individual request delegate can be specified in-line as an anonymous method (called in-line middleware), or it can be defined in a reusable class. These reusable classes and in-line anonymous methods are middleware, also called middleware components. Each middleware component in the request pipeline is responsible for invoking the next component in the pipeline or short-circuiting the pipeline. When a middleware short-circuits, it's called a terminal middleware because it prevents further middleware from processing the request.

Migrate HTTP handlers and modules to ASP.NET Core middleware explains the difference between request pipelines in ASP.NET Core and ASP.NET 4.x and provides additional middleware samples.

Create a middleware pipeline with IApplicationBuilder

The ASP.NET Core request pipeline consists of a sequence of request delegates, called one after the other. The following diagram demonstrates the concept. The thread of execution follows the black arrows.

Each delegate can perform operations before and after the next delegate. Exception-handling delegates should be called early in the pipeline, so they can catch exceptions that occur in later stages of the pipeline.

The simplest possible ASP.NET Core app sets up a single request delegate that handles all requests. This case doesn't include an actual request pipeline. Instead, a single anonymous function is called in response to every HTTP request.

The first Run delegate terminates the pipeline.

Chain multiple request delegates together with Use. The next parameter represents the next delegate in the pipeline. You can short-circuit the pipeline by not calling the next parameter. You can typically perform actions both before and after the next delegate, as the following example demonstrates:

When a delegate doesn't pass a request to the next delegate, it's called short-circuiting the request pipeline. Short-circuiting is often desirable because it avoids unnecessary work. For example, Static File Middleware can act as a terminal middleware by processing a request for a static file and short-circuiting the rest of the pipeline. Middleware added to the pipeline before the middleware that terminates further processing still processes code after their next.Invoke statements. However, see the following warning about attempting to write to a response that has already been sent.

Warning

Don't call next.Invoke after the response has been sent to the client. Changes to HttpResponse after the response has started throw an exception. For example, changes such as setting headers and a status code throw an exception. Writing to the response body after calling next:

  • May cause a protocol violation. For example, writing more than the stated Content-Length.
  • May corrupt the body format. For example, writing an HTML footer to a CSS file.

HasStarted is a useful hint to indicate if headers have been sent or the body has been written to.

Middleware order

The order that middleware components are added in the Startup.Configure method defines the order in which the middleware components are invoked on requests and the reverse order for the response. The order is critical for security, performance, and functionality.

The following Startup.Configure method adds security related middleware components in the recommended order:

In the preceding code:

  • Middleware that is not added when creating a new web app with individual users accounts is commented out.
  • Not every middleware needs to go in this exact order, but many do. For example, UseCors and UseAuthentication must go in the order shown.

The following Startup.Configure method adds middleware components for common app scenarios:

  1. Exception/error handling
    • When the app runs in the Development environment:
      • Developer Exception Page Middleware (UseDeveloperExceptionPage) reports app runtime errors.
      • Database Error Page Middleware (Microsoft.AspNetCore.Builder.DatabaseErrorPageExtensions.UseDatabaseErrorPage) reports database runtime errors.
    • When the app runs in the Production environment:
      • Exception Handler Middleware (UseExceptionHandler) catches exceptions thrown in the following middlewares.
      • HTTP Strict Transport Security Protocol (HSTS) Middleware (UseHsts) adds the Strict-Transport-Security header.
  2. HTTPS Redirection Middleware (UseHttpsRedirection) redirects HTTP requests to HTTPS.
  3. Static File Middleware (UseStaticFiles) returns static files and short-circuits further request processing.
  4. Cookie Policy Middleware (UseCookiePolicy) conforms the app to the EU General Data Protection Regulation (GDPR) regulations.
  5. Authentication Middleware (UseAuthentication) attempts to authenticate the user before they're allowed access to secure resources.
  6. Session Middleware (UseSession) establishes and maintains session state. If the app uses session state, call Session Middleware after Cookie Policy Middleware and before MVC Middleware.
  7. MVC (UseMvc) to add MVC to the request pipeline.

In the preceding example code, each middleware extension method is exposed on IApplicationBuilder through the Microsoft.AspNetCore.Builder namespace.

UseExceptionHandler is the first middleware component added to the pipeline. Therefore, the Exception Handler Middleware catches any exceptions that occur in later calls.

Static File Middleware is called early in the pipeline so that it can handle requests and short-circuit without going through the remaining components. The Static File Middleware provides no authorization checks. Any files served by Static File Middleware, including those under wwwroot, are publicly available. For an approach to secure static files, see Static files in ASP.NET Core.

If the request isn't handled by the Static File Middleware, it's passed on to the Authentication Middleware (UseAuthentication), which performs authentication. Authentication doesn't short-circuit unauthenticated requests. Although Authentication Middleware authenticates requests, authorization (and rejection) occurs only after MVC selects a specific Razor Page or MVC controller and action.

The following example demonstrates a middleware order where requests for static files are handled by Static File Middleware before Response Compression Middleware. Static files aren't compressed with this middleware order. The MVC responses from UseMvcWithDefaultRoute can be compressed.

Use, Run, and Map

Configure the HTTP pipeline using Use, Run, and Map. The Use method can short-circuit the pipeline (that is, if it doesn't call a next request delegate). Run is a convention, and some middleware components may expose Run[Middleware] methods that run at the end of the pipeline.

Middleware

Map extensions are used as a convention for branching the pipeline. Map branches the request pipeline based on matches of the given request path. If the request path starts with the given path, the branch is executed.

The following table shows the requests and responses from http://localhost:1234 using the previous code.

RequestResponse
localhost:1234Hello from non-Map delegate.
localhost:1234/map1Map Test 1
localhost:1234/map2Map Test 2
localhost:1234/map3Hello from non-Map delegate.

When Map is used, the matched path segments are removed from HttpRequest.Path and appended to HttpRequest.PathBase for each request.

MapWhen branches the request pipeline based on the result of the given predicate. Any predicate of type Func<HttpContext, bool> can be used to map requests to a new branch of the pipeline. In the following example, a predicate is used to detect the presence of a query string variable branch:

The following table shows the requests and responses from http://localhost:1234 using the previous code.

RequestResponse
localhost:1234Hello from non-Map delegate.
localhost:1234/?branch=mainBranch used = main

Map supports nesting, for example:

Map can also match multiple segments at once:

Built-in middleware

ASP.NET Core ships with the following middleware components. The Order column provides notes on middleware placement in the request processing pipeline and under what conditions the middleware may terminate request processing. When a middleware short-circuits the request processing pipeline and prevents further downstream middleware from processing a request, it's called a terminal middleware. For more information on short-circuiting, see the Create a middleware pipeline with IApplicationBuilder section.

MiddlewareDescriptionOrder
AuthenticationProvides authentication support.Before HttpContext.User is needed. Terminal for OAuth callbacks.
Cookie PolicyTracks consent from users for storing personal information and enforces minimum standards for cookie fields, such as secure and SameSite.Before middleware that issues cookies. Examples: Authentication, Session, MVC (TempData).
CORSConfigures Cross-Origin Resource Sharing.Before components that use CORS.
DiagnosticsSeveral separate middlewares that provide a developer exception page, exception handling, status code pages, and the default web page for new apps.Before components that generate errors. Terminal for exceptions or serving the default web page for new apps.
Forwarded HeadersForwards proxied headers onto the current request.Before components that consume the updated fields. Examples: scheme, host, client IP, method.
Health CheckChecks the health of an ASP.NET Core app and its dependencies, such as checking database availability.Terminal if a request matches a health check endpoint.
HTTP Method OverrideAllows an incoming POST request to override the method.Before components that consume the updated method.
HTTPS RedirectionRedirect all HTTP requests to HTTPS.Before components that consume the URL.
HTTP Strict Transport Security (HSTS)Security enhancement middleware that adds a special response header.Before responses are sent and after components that modify requests. Examples: Forwarded Headers, URL Rewriting.
MVCProcesses requests with MVC/Razor Pages.Terminal if a request matches a route.
OWINInterop with OWIN-based apps, servers, and middleware.Terminal if the OWIN Middleware fully processes the request.
Response CachingProvides support for caching responses.Before components that require caching.
Response CompressionProvides support for compressing responses.Before components that require compression.
Request LocalizationProvides localization support.Before localization sensitive components.
Endpoint RoutingDefines and constrains request routes.Terminal for matching routes.
SessionProvides support for managing user sessions.Before components that require Session.
Static FilesProvides support for serving static files and directory browsing.Terminal if a request matches a file.
URL RewriteProvides support for rewriting URLs and redirecting requests.Before components that consume the URL.
WebSocketsEnables the WebSockets protocol.Before components that are required to accept WebSocket requests.

Additional resources