SlideShare a Scribd company logo
Routing Internals
Łukasz Łysik
ASP.NET MVC 4 Study Group
Agenda
• Routes Registration
• Routes Registration for Areas
• How routing works?
• Generating URLs
• Debugging routes
ROUTES REGISTRATION
Routes Registration Overview
Are there any
restrictions here?
Routes Registration Overview
Routes Registration MapRoute
RouteCollectionExtensions:
Routes Registration Route class
MySite/{controller}-{action}/{id}
Routes
Registration
Route class ParsedRoute
ParsedRoute
ContentPathSegment
LiteralSubsegment
(„MySite”)
SeparatorPathSegment ContentPathSegment
ParameterSubsegment
{controller}
LiteralSubsegment „-”
ParameterSubsegment
{action}
SeparatorPathSegment ContentPathSegment
ParameterSubsegments
{id}
Routes
Registration
Route class Constraints
Routes
Registration
Route class
Custom
Constraints
Problem: We want to have mechanism which closes our web site for
maintenance for specified period of time.
Inputs:
Routes
Registration
Route class
Custom
Constraints
Coding
Routes
Registration
Route class
Custom
Constraints
Routes
Registration
Route class
Custom
Constraints
Routes
Registration
Route class DataTokens
• Contain values associated with the route that are not used when ASP.NET
routing determines whether a route matches a request.
• Custom data tokens can be defined and used by custom logic in route
handler, controller, action, etc.
• Predefined DataTokens are related to Areas.
ROUTES REGISTRATION FOR AREAS
Routes Registration for Areas Overview
Routes Registration for Areas Overview
Problem: Multiple controllers with the same names
Routes Registration for Areas MapRoute
Routes Registration for Areas DataTokens collection
Area
Current area name.
Namespaces
Namespaces to search for
controllers.
UseNamespaceFallback
Set to „false” to disable searching
in other namespaces.
Q: In which part of request pipeline these two DataTokens are used?
A: In DefaultControllerFactory.
Routes Registration for Areas Usage of DataTokens
DefaultControllerFactory:
HOW ROUTING WORKS?
Route 1
URL 1
ParsedRoute 1
Defaults 1
Constraints 1
DataTokens 1
RouteHandler 1
Route 2
URL 2
ParsedRoute 2
Defaults 2
Constraints 2
DataTokens 2
RouteHandler 2
… Route n
URL n
ParsedRoute n
Defaults n
Constraints n
DataTokens n
RouteHandler n
How Routing Works? RouteTable.Routes
How Routing Works? Routing Process (1)
UrlRoutingModule RouteTable.Routes
Do you have any routes
for this context?
Route 1 Route 2 Route n
. . .
ParsedRoute matches current URL?
Do I have any constraints?
Process constraints.
Constraints satisfied?
Return null.Build and return RouteData.
No
No
No
Yes
Yes
How Routing Works? Routing Process (2)
UrlRoutingModule
RouteData
(based on Route 2)
Give me IRouteHandler
IRouteHandler
Give me IHttpHandler
Tell IIS to use
IHttpHandler which I
got from matched
Route.
How Routing Works? RouteData
How Routing Works? Route.ProcessConstraint
How Routing Works? Route.GetRouteData
How Routing Works? Route.ProcessConstraint
URL GENERATION
URL Generation Overview
URL Generation Examples (1)
URL Generation Examples (2)
URL Generation Matching Algorithm
RouteCollection.GetVirtualPath(Supplied values)
Does Route have required parameters?
Did the call to GetVirtualPath specify a value for
each required parameter?
Does Route have default values that do not
correspond to URL parameter?
Does true value for that default, if specified,
match the specified value?
Process constraints
Yes
Yes
Yes
No
Required = with no default value
No match!
No
No
URL: “todo/{action}”
Defaults:
controller=home
action=index
No match!
No
Yes
DEBUGGING ROUTES
• Possible problems:
– Routes don’t work.
– URL is routed to wrong controller/action.
– DataTokens values are missing (are wrong).
– Constraints don’t work.
• What we need?
– Tool that will tell us which routes are being
matched, what RouteData parameters and
DataTokens are.
Debugging Routes Problems
Debugging Routes How?
Q: How to write a tool that will debug routes?
Q: What is the name of static class which stores routes?
Q: Which request pipeline element uses RouteTable.Routes?
A: RouteTable.Routes
A: UrlRoutingModule
Demo
Debugging Routes Coding session
Debugging Routes Coding session
• RouteDebugger by Phil
Haack:
– http://haacked.com/archive/20
11/04/12/routedebugger-
2.aspx
• How it works:
– Registers own HTTP module.
– Attach to Request_End event.
– Writes route data at the bottom
of each view.
Debugging Routes RouteDebugger 2.0
References
Professional ASP.NET MVC 4
(http://www.amazon.co.uk/Professional-ASP-NET-MVC-Wrox-Guides/dp/111834846X)
Questions?

More Related Content

PPTX
ASP.NET Routing & MVC
PPT
Backbone js
ODP
Spray - Build RESTfull services in scala
PDF
Spring Mvc Rest
PPTX
ASP.NET MVC 4 Request Pipeline Internals
PDF
Spring MVC Annotations
PPT
Intoduction to Play Framework
PPT
Spring MVC Basics
ASP.NET Routing & MVC
Backbone js
Spray - Build RESTfull services in scala
Spring Mvc Rest
ASP.NET MVC 4 Request Pipeline Internals
Spring MVC Annotations
Intoduction to Play Framework
Spring MVC Basics

What's hot (17)

ODP
Http programming in play
PPTX
Spring MVC Architecture Tutorial
PDF
AAI 2236-Using the New Java Concurrency Utilities with IBM WebSphere
PDF
Spring annotation
PDF
Tips and Tricks For Faster Asp.NET and MVC Applications
KEY
Geotalk presentation
PDF
Reactive Thinking in Java
PPTX
Flask & Flask-restx
PPTX
Spring 3.x - Spring MVC - Advanced topics
PPTX
Spring core
PDF
Lecture 5 JSTL, custom tags, maven
PPT
Programming Server side with Sevlet
PPTX
How to get full power from WebApi
PDF
Reactive programming in Angular 2
PPTX
Asp.Net Mvc
PDF
The Spring Update
PPTX
Introduction to ASP.Net MVC
Http programming in play
Spring MVC Architecture Tutorial
AAI 2236-Using the New Java Concurrency Utilities with IBM WebSphere
Spring annotation
Tips and Tricks For Faster Asp.NET and MVC Applications
Geotalk presentation
Reactive Thinking in Java
Flask & Flask-restx
Spring 3.x - Spring MVC - Advanced topics
Spring core
Lecture 5 JSTL, custom tags, maven
Programming Server side with Sevlet
How to get full power from WebApi
Reactive programming in Angular 2
Asp.Net Mvc
The Spring Update
Introduction to ASP.Net MVC
Ad

Similar to ASP.NET MVC 4 - Routing Internals (14)

PDF
.NET Core, ASP.NET Core Course, Session 10
PPTX
Mvc3 part2
PPTX
ASP.NET Routing Deep Dive
PPTX
Murach : HOW to work with controllers and routing
DOC
Custom routing in asp.net mvc
PPTX
Chapter5.pptx
PPTX
Asp.Net Mvc Internals & Extensibility
PDF
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
PPTX
reactjs-reactrouter-1607111dfdfdf55618.pptx
PPTX
reactjs-reactrouter-160711155618 (1).pptx
PDF
Asp.net mvc internals & extensibility
PPTX
Routing in symfony
PDF
Workshop 21: React Router
PPTX
ASP.Net MVC 4 [Part - 2]
.NET Core, ASP.NET Core Course, Session 10
Mvc3 part2
ASP.NET Routing Deep Dive
Murach : HOW to work with controllers and routing
Custom routing in asp.net mvc
Chapter5.pptx
Asp.Net Mvc Internals & Extensibility
Custom URL Re-Writing/Routing using Attribute Routes in MVC 4 Web APIs
reactjs-reactrouter-1607111dfdfdf55618.pptx
reactjs-reactrouter-160711155618 (1).pptx
Asp.net mvc internals & extensibility
Routing in symfony
Workshop 21: React Router
ASP.Net MVC 4 [Part - 2]
Ad

Recently uploaded (20)

PDF
Advanced IT Governance
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPT
Teaching material agriculture food technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Sensors and Actuators in IoT Systems using pdf
PPTX
Cloud computing and distributed systems.
PPTX
Big Data Technologies - Introduction.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Advanced IT Governance
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Electronic commerce courselecture one. Pdf
Telecom Fraud Prevention Guide | Hyperlink InfoSystem
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Teaching material agriculture food technology
Understanding_Digital_Forensics_Presentation.pptx
Advanced Soft Computing BINUS July 2025.pdf
GamePlan Trading System Review: Professional Trader's Honest Take
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
MYSQL Presentation for SQL database connectivity
Dropbox Q2 2025 Financial Results & Investor Presentation
NewMind AI Monthly Chronicles - July 2025
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Sensors and Actuators in IoT Systems using pdf
Cloud computing and distributed systems.
Big Data Technologies - Introduction.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

ASP.NET MVC 4 - Routing Internals