<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/the-asp-net-core-pipeline-order-nobody-explains-properly-4qy8txaca" -->

---
title: The ASP .NET Core Pipeline Order Nobody Explains Properly
description: A deep dive into the ASP.NET Core middleware pipeline explaining how requests flow through Use, Run, and Map, why order matters (especially authentication...
canonical: https://daily.dev/posts/the-asp-net-core-pipeline-order-nobody-explains-properly-4qy8txaca
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: The ASP .NET Core Pipeline Order Nobody Explains Properly | daily.dev
og:description: A deep dive into the ASP.NET Core middleware pipeline explaining how requests flow through Use, Run, and Map, why order matters (especially authentication...
og:url: https://daily.dev/posts/the-asp-net-core-pipeline-order-nobody-explains-properly-4qy8txaca
og:image: https://api.daily.dev/og/posts/4qY8TXACA.png
og:image:alt: The ASP .NET Core Pipeline Order Nobody Explains Properly
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# The ASP .NET Core Pipeline Order Nobody Explains Properly

**[Waseem .NET Newsletter](https://daily.dev/sources/mwaseemzakir)** · 8 min read · 11 upvotes · 0 comments

## Summary

A deep dive into the ASP.NET Core middleware pipeline explaining how requests flow through Use, Run, and Map, why order matters (especially authentication before authorization), how short-circuiting works, the difference between UseWhen and MapWhen, and when to choose middleware versus filters. Includes code examples for inline, convention-based, and factory-based (IMiddleware) custom middleware.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://mwaseemzakir.substack.com/p/the-asp-net-core-pipeline-order-nobody>

## Questions this post answers

### What is the difference between UseWhen and MapWhen in ASP.NET Core?

UseWhen branches on any condition and rejoins the main pipeline afterward as long as nothing inside the branch short-circuits, while MapWhen also branches on any condition but behaves like Map, meaning the branch never rejoins the main pipeline. Use UseWhen when you need conditional middleware that still flows into shared authorization and controllers; use MapWhen or Map for a dead-end branch, such as a beta feature path.

_Developers designing conditional middleware branches can compare these patterns and pitfalls on daily.dev._

### Why does swapping UseAuthentication and UseAuthorization in ASP.NET Core Program.cs break auth silently?

Authentication figures out who the user is, and authorization decides whether that identified user can access what they're requesting, so authorization must run after authentication in the middleware pipeline. Registering them in the wrong order produces broken access-control behavior that looks like an unrelated bug rather than an obvious ordering mistake, since middleware executes strictly in registration order.

_Teams debugging odd auth failures can check pipeline ordering guidance like this on daily.dev._

### What does the Map method do to Request.Path in ASP.NET Core middleware?

Map creates a separate pipeline branch based on a request path prefix, and it strips the matched path segment off Request.Path, moving it into Request.PathBase. Code running inside that branch that reads Request.Path will see the path without the prefix that triggered the branch, which can surprise developers relying on the full original path inside path-based branches.

_Developers wiring up path-based pipeline branches can revisit gotchas like this via daily.dev._

## Similar posts on daily.dev

- [ASP.NET Core Middleware: Building and Using the Request Pipeline](https://daily.dev/posts/asp-net-core-middleware-building-and-using-the-request-pipeline-tav1b2ck7) · We Are .NET · 1 upvotes · 0 comments
- [ASP.NET Core 11 Request Pipeline Performance Deep Dive](https://daily.dev/posts/asp-net-core-11-request-pipeline-performance-deep-dive-y8dxv0kx8) · C\# Corner · 2 upvotes · 0 comments
- [Pipeline vs Chain of Responsibility vs ASP.NET Core Middleware](https://daily.dev/posts/pipeline-vs-chain-of-responsibility-vs-asp-net-core-middleware-rdd5sjnru) · We Are .NET · 0 upvotes · 0 comments
- [Correct Order for CORS, Authentication, and Authorization in ASP.NET Core](https://daily.dev/posts/correct-order-for-cors-authentication-and-authorization-in-asp-net-core-8zxkwml07) · C\# Corner · 0 upvotes · 0 comments
- [30 ASP.NET Core Interview Questions That Actually Get Asked in 2026](https://daily.dev/posts/30-asp-net-core-interview-questions-that-actually-get-asked-in-2026-b4ndnfwkf) · Code with Mukesh · 7 upvotes · 2 comments

---

Tags: [#authentication](https://daily.dev/tags/authentication), [#c#](https://daily.dev/tags/c#), [#aspnet](https://daily.dev/tags/aspnet)

[View this post on daily.dev](https://daily.dev/posts/the-asp-net-core-pipeline-order-nobody-explains-properly-4qy8txaca)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"The ASP .NET Core Pipeline Order Nobody Explains Properly","url":"https://daily.dev/posts/the-asp-net-core-pipeline-order-nobody-explains-properly-4qy8txaca","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/the-asp-net-core-pipeline-order-nobody-explains-properly-4qy8txaca"},"datePublished":"2026-08-15T04:09:00.969Z","dateModified":"2026-09-14T08:20:43.918Z","description":"A deep dive into the ASP.NET Core middleware pipeline explaining how requests flow through Use, Run, and Map, why order matters (especially authentication...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/079cc954fc880e7486ee064990518690?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/079cc954fc880e7486ee064990518690?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Waseem .NET Newsletter","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Waseem .NET Newsletter","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/a10ec420048a48bf86f6889f2de88180","url":"https://daily.dev/sources/mwaseemzakir"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/the-asp-net-core-pipeline-order-nobody-explains-properly-4qy8txaca","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":11},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"authentication,c#,aspnet","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Waseem .NET Newsletter","item":"https://daily.dev/sources/mwaseemzakir"},{"@type":"ListItem","position":3,"name":"The ASP .NET Core Pipeline Order Nobody Explains Properly"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/the-asp-net-core-pipeline-order-nobody-explains-properly-4qy8txaca#faq","mainEntity":[{"@type":"Question","name":"What is the difference between UseWhen and MapWhen in ASP.NET Core?","acceptedAnswer":{"@type":"Answer","text":"UseWhen branches on any condition and rejoins the main pipeline afterward as long as nothing inside the branch short-circuits, while MapWhen also branches on any condition but behaves like Map, meaning the branch never rejoins the main pipeline. Use UseWhen when you need conditional middleware that still flows into shared authorization and controllers; use MapWhen or Map for a dead-end branch, such as a beta feature path. Developers designing conditional middleware branches can compare these patterns and pitfalls on daily.dev."}},{"@type":"Question","name":"Why does swapping UseAuthentication and UseAuthorization in ASP.NET Core Program.cs break auth silently?","acceptedAnswer":{"@type":"Answer","text":"Authentication figures out who the user is, and authorization decides whether that identified user can access what they're requesting, so authorization must run after authentication in the middleware pipeline. Registering them in the wrong order produces broken access-control behavior that looks like an unrelated bug rather than an obvious ordering mistake, since middleware executes strictly in registration order. Teams debugging odd auth failures can check pipeline ordering guidance like this on daily.dev."}},{"@type":"Question","name":"What does the Map method do to Request.Path in ASP.NET Core middleware?","acceptedAnswer":{"@type":"Answer","text":"Map creates a separate pipeline branch based on a request path prefix, and it strips the matched path segment off Request.Path, moving it into Request.PathBase. Code running inside that branch that reads Request.Path will see the path without the prefix that triggered the branch, which can surprise developers relying on the full original path inside path-based branches. Developers wiring up path-based pipeline branches can revisit gotchas like this via daily.dev."}}]}
```

