SlideShare a Scribd company logo
1 of 41
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

What's hot

Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
backdoor
 
Introduction to ASP.Net MVC
Introduction to ASP.Net MVCIntroduction to ASP.Net MVC
Introduction to ASP.Net MVC
Sagar Kamate
 

What's hot (17)

Http programming in play
Http programming in playHttp programming in play
Http programming in play
 
Spring MVC Architecture Tutorial
Spring MVC Architecture TutorialSpring MVC Architecture Tutorial
Spring MVC Architecture Tutorial
 
AAI 2236-Using the New Java Concurrency Utilities with IBM WebSphere
AAI 2236-Using the New Java Concurrency Utilities with IBM WebSphereAAI 2236-Using the New Java Concurrency Utilities with IBM WebSphere
AAI 2236-Using the New Java Concurrency Utilities with IBM WebSphere
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
 
Tips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC ApplicationsTips and Tricks For Faster Asp.NET and MVC Applications
Tips and Tricks For Faster Asp.NET and MVC Applications
 
Geotalk presentation
Geotalk presentationGeotalk presentation
Geotalk presentation
 
Reactive Thinking in Java
Reactive Thinking in JavaReactive Thinking in Java
Reactive Thinking in Java
 
Flask & Flask-restx
Flask & Flask-restxFlask & Flask-restx
Flask & Flask-restx
 
Spring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topicsSpring 3.x - Spring MVC - Advanced topics
Spring 3.x - Spring MVC - Advanced topics
 
Spring core
Spring coreSpring core
Spring core
 
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, maven
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
 
How to get full power from WebApi
How to get full power from WebApiHow to get full power from WebApi
How to get full power from WebApi
 
Reactive programming in Angular 2
Reactive programming in Angular 2Reactive programming in Angular 2
Reactive programming in Angular 2
 
Asp.Net Mvc
Asp.Net MvcAsp.Net Mvc
Asp.Net Mvc
 
The Spring Update
The Spring UpdateThe Spring Update
The Spring Update
 
Introduction to ASP.Net MVC
Introduction to ASP.Net MVCIntroduction to ASP.Net MVC
Introduction to ASP.Net MVC
 

Similar to ASP.NET MVC 4 - Routing Internals

MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
Dilip Patel
 

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

.NET Core, ASP.NET Core Course, Session 10
.NET Core, ASP.NET Core Course, Session 10.NET Core, ASP.NET Core Course, Session 10
.NET Core, ASP.NET Core Course, Session 10
 
ASP.NET - Building Web Application..in the right way!
ASP.NET - Building Web Application..in the right way!ASP.NET - Building Web Application..in the right way!
ASP.NET - Building Web Application..in the right way!
 
ASP.NET - Building Web Application..in the right way!
ASP.NET - Building Web Application..in the right way!ASP.NET - Building Web Application..in the right way!
ASP.NET - Building Web Application..in the right way!
 
SAP FIORI COEP Pune - pavan golesar (ppt)
SAP FIORI COEP Pune - pavan golesar (ppt)SAP FIORI COEP Pune - pavan golesar (ppt)
SAP FIORI COEP Pune - pavan golesar (ppt)
 
Asp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design PatternAsp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design Pattern
 
Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...Sherlock Homepage - A detective story about running large web services - NDC ...
Sherlock Homepage - A detective story about running large web services - NDC ...
 
Sherlock Homepage (Maarten Balliauw)
Sherlock Homepage (Maarten Balliauw)Sherlock Homepage (Maarten Balliauw)
Sherlock Homepage (Maarten Balliauw)
 
Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...Sherlock Homepage - A detective story about running large web services (VISUG...
Sherlock Homepage - A detective story about running large web services (VISUG...
 
REST principle & Playframework Routes
REST principle & Playframework RoutesREST principle & Playframework Routes
REST principle & Playframework Routes
 
Tracing Micro Services with OpenTracing
Tracing Micro Services with OpenTracingTracing Micro Services with OpenTracing
Tracing Micro Services with OpenTracing
 
What is WAAT?
What is WAAT?What is WAAT?
What is WAAT?
 
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
Que hay de nuevo en Visual Studio 2013 y ASP.NET 5.1
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5
 
Java colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rsJava colombo-deep-dive-into-jax-rs
Java colombo-deep-dive-into-jax-rs
 
ASP.NET MVC introduction
ASP.NET MVC introductionASP.NET MVC introduction
ASP.NET MVC introduction
 
ASP.NET MVC Performance
ASP.NET MVC PerformanceASP.NET MVC Performance
ASP.NET MVC Performance
 
Mvc3 part2
Mvc3   part2Mvc3   part2
Mvc3 part2
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
CTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVCCTTDNUG ASP.NET MVC
CTTDNUG ASP.NET MVC
 
There is time for rest
There is time for rest There is time for rest
There is time for rest
 

Recently uploaded

Recently uploaded (20)

JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
API Governance and Monetization - The evolution of API governance
API Governance and Monetization -  The evolution of API governanceAPI Governance and Monetization -  The evolution of API governance
API Governance and Monetization - The evolution of API governance
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 

ASP.NET MVC 4 - Routing Internals