liveBook · Manning

Map

As explained in ASP.NET Core in Action, 3e

MapMethods is an ASP.NET Core endpoint-mapping method for associating a URL pattern and handler with one or more specified HTTP methods.

Map branches the ASP.NET Core middleware pipeline according to a request URL path. Requests matching a specified path prefix enter the branch; other requests continue through the main pipeline. section 31.1.2

Use Map when a small group of requests needs different middleware behavior:

  • Specify a path prefix, such as /ping. section 31.1.2
  • Keep the main pipeline available for requests that do not match. section 31.1.2
  • Remember that a matched path segment moves from HttpContext.Path to PathBase. section 31.4

A /ping branch

app.Map("/ping", branch => { branch.UseExceptionHandler(); branch.Run(async context => { context.Response.ContentType = "text/plain"; await context.Response.WriteAsync("pong"); }); }); A request to /ping receives pong through the branch, while other requests continue to the application’s main middleware pipeline.

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains prefix matching, branch execution, and PathBase handling, while deferring route parameters and favoring endpoint routing.
Examples
Uses a /ping branch that applies exception handling and returns plain-text pong through terminal middleware.
What it assumes
Assumes familiarity with ASP.NET Core middleware and introduces branching as an alternative to a single sequential pipeline.
What you can do after
Configure a path-based middleware branch and predict whether requests follow the branch or the main pipeline.
How it connects
Connects middleware pipelines with Run, Use, MapWhen, endpoint routing, and health-check endpoints.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.