Skip to main content

Explain the difference between Use, Run, and Map in middleware configuration.

Junior .NET Core
Quick Answer Use(): adds middleware that can call next รขโ‚ฌโ€ used for middleware that performs work and continues the pipeline. Run(): terminal middleware รขโ‚ฌโ€ never calls next, short-circuits the pipeline. Map(): branches the pipeline based on a URL prefix รขโ‚ฌโ€ creates a sub-pipeline for that branch. Use is the most common; Run ends the pipeline; Map enables path-based branching.

Answer

  • Use โ€“ Adds middleware that can process the request and optionally call the next middleware via a next delegate.
  • Run โ€“ Adds terminal middleware that does not call the next component; it ends the pipeline.
  • Map โ€“ Branches the pipeline based on the request path, creating sub-pipelines for specific URL segments.

Together, they give fine-grained control over the shape and branching of the request pipeline.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice