Difference between app.Use, app.UseMiddleware, app.Run, and?
app.Map
Method Description
app.Use Adds middleware that can call next in the
pipeline.
app.UseMiddlewar
e<T>()
Adds a custom middleware class.
app.Run Terminal middleware – does not call next. Ends
the pipeline.
app.Map Branches the pipeline based on URL path (e.g.
/api).
Example:
app.Use(async (context, next) => {
await next(); // go to next middleware
});
app.Run(async context => {
await context.Response.WriteAsync("Hello World"); //
terminates pipeline
});