SlideShare una empresa de Scribd logo
1 de 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?

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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 a 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 a 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
 

Último

Último (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

ASP.NET MVC 4 - Routing Internals