SlideShare uma empresa 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?

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante 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
 

Semelhante 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)

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
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
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
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
[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
 
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
 
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
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 

ASP.NET MVC 4 - Routing Internals