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.
