SlideShare a Scribd company logo
1 of 21
ASP.NET ROUTING
DEEP DIVE
Stacy Vicknair
Sparkhound
0
Welcome to Houston TechFest
Thank you for being a part of the
7th Annual Houston TechFest!
• Please turn off all electronic devices or set them to vibrate.
• If you must take a phone call, please do so in the lobby so as not
to disturb others.
• Thanks to our Diamond Sponsors:

1
Information
• Speaker presentation slides will be available at
www.houstontechfest.org within a week
• Don’t forget to complete the Bingo card to be
eligible for door prizes

2
ABOUT ME
Stacy Vicknair, MVP
Senior Development Consultant
Blog
http://www.wtfnext.com
Toastmasters
http://www.toastmasters.org
http://www.batonrougespeaks.com

Twitter: @svickn
Email: stacy.vicknair@sparkhound.com
“BE A HERO. GROW A BEARD.”
The Sparkhound Foundation is sponsoring the growth of
facial hair to raise Prostate Cancer Awareness.
Through Septembeard we will
raise funds for the research and
treatment of prostate cancer.

Want to join us? Learn more at Septembeard.org.
Agenda
•
•
•
•
•
•

What Is Routing?
Out of the Box ASP.NET MVC Routing
Customizing ASP.NET MVC Routing
Unit Testing ASP.NET MVC Routes
Routing In ASP.NET WebForms
Helpful Links

5
What is ASP.NET Routing?
“ASP.NET routing enables you to use URLs that do not have
to map to specific files in a Web site.”
- http://msdn.microsoft.com/en-us/library/cc668201.aspx

www.mysite.com/categories.aspx?categoryName=sports
www.mysite.com/categories/sports

6

6
HttpModules and HttpHandlers

7
ASP.NET Routing (System.Web.Routing)

8
ASP.NET MVC Routing (System.Web.Mvc)

9
Out of the box MVC Routing
• Routes.IgnoreRoute()
– System.Web.Routing.StopRoutingHandler

• Routes.MapRoute()
– System.Web.Mvc.RouteCollectionExtensions
– Parameters

1
0

• string name – “MyUniqueName”
• string url – “{controller}/{action}/{id}”
• Object defaults new { controller = "Home", action = "Index”}
• Object constraints – new {id = “[0-9]+”}
• string[] namespaces - new[] { "MyProject.MyControllers"}
10
DEMO – Out of the box MVC Routing

1
1

11
Customizing ASP.NET MVC Routing
• Three main areas for routing customization
– RouteConstraints
• Implementing constraints that require more logic than RegEx
• Created by implementing System.Web.Routing.IRouteConstraint

– Routes
• Allow for control over how route data is parsed or route paths are
determined
• Created by subclassing System.Web.Routing.RouteBase
• Default is Route ex. RouteCollection.Add(new Route(…))

– RouteHandlers
• Allow for preprocessing before default RouteHandler behavior
– ex. RouteData modifications
12
DEMO – RouteConstraints and Routes

1
3

13
Unit Testing Routes
• Use RouteTable.Routes.GetRouteData()
– Requires mocked HttpContext (to provide the URL)

• Enumerate over RouteData to ensure the proper
information is returned
• Alternative is MVCContrib
– string.ShouldMapTo<T>(c => c.Action());
– Not “officially” ported to MVC4 by Ndepend yet.
• Search NuGet for MvcContrib.Mvc4 to find a port

14
DEMO – Unit Testing with Routes

1
5

15
Adding Routing to ASP.NET WebForms
• In the Global.asax, add a reference to System.Web.Routing
• Add routes via RouteTable.Routes.MapPageRoute()
• Update links to use routes
– RouteUrl
– GetVirtualPath

• Get Routing Data
– RouteValue
– RouteData.Values[]

16
DEMO – Routes in ASP.NET WebForms

1
7

17
Agenda
•
•
•
•
•
•

What Is Routing?
Out of the Box ASP.NET MVC Routing
Customizing ASP.NET MVC Routing
Unit Testing ASP.NET MVC Routes
Routing In ASP.NET WebForms
Helpful Links

18
Helpful Links
THE MOST IMPORTANT LINK I COULD EVER TELL YOU:
http://aspnetwebstack.codeplex.com/
http://mvccontrib.codeplex.com/ - MVCContrib
http://msdn.microsoft.com/en-us/library/dd329551.aspx - Webforms
Google or Bing: ASP.NET Routing

Slides / Code will be available at http://www.wtfnext.com
References:
http://www.15seconds.com/Issue/020417.htm
http://msdn.microsoft.com/en-us/library/cc668201.aspx
http://blogs.msdn.com/b/alikl/archive/2009/04/02/how-asp-net-mvc-works-for-aspiring-architects-2.aspx
http://blog.didsburydesign.com/2010/02/how-to-allow-hyphens-in-urls-using-asp-net-mvc-2/
http://stackoverflow.com/questions/1107507/asp-net-mvc-custom-route-handler-constraint
http://haacked.com/archive/2007/12/17/testing-routes-in-asp.net-mvc.aspx

19
Please Leave Feedback During Q&A
If you leave session
feedback and
provide contact
information, you
will be qualified for
a prize
Scan the QR code
to the right or go to
bit.ly/htf130202
20

More Related Content

Similar to Deep Dive into ASP.NET Routing

Who's Watching, by Geoff Huston [APNIC 38 / Technical Keynote]
Who's Watching, by Geoff Huston [APNIC 38 / Technical Keynote]Who's Watching, by Geoff Huston [APNIC 38 / Technical Keynote]
Who's Watching, by Geoff Huston [APNIC 38 / Technical Keynote]APNIC
 
Mulesoft Pune Meetup Deck - Apr 2020
Mulesoft Pune Meetup Deck - Apr 2020Mulesoft Pune Meetup Deck - Apr 2020
Mulesoft Pune Meetup Deck - Apr 2020Santosh Ojha
 
VTA Hack My Ride Lightning Talks
VTA Hack My Ride Lightning TalksVTA Hack My Ride Lightning Talks
VTA Hack My Ride Lightning TalksSCVTA
 
Jetstream: Adding Cloud-based Computing to the National Cyberinfrastructure
Jetstream: Adding Cloud-based Computing to the National CyberinfrastructureJetstream: Adding Cloud-based Computing to the National Cyberinfrastructure
Jetstream: Adding Cloud-based Computing to the National CyberinfrastructureMatthew Vaughn
 
Slides internet technology
Slides internet technologySlides internet technology
Slides internet technologyInexk Pedrero
 
Jetstream - Adding Cloud-based Computing to the National Cyberinfrastructure
Jetstream - Adding Cloud-based Computing to the National CyberinfrastructureJetstream - Adding Cloud-based Computing to the National Cyberinfrastructure
Jetstream - Adding Cloud-based Computing to the National Cyberinfrastructureinside-BigData.com
 
Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)
Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)
Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)Kevin Griffin
 
Power to the People: Manipulating SharePoint with Client-Side JavaScript
Power to the People:  Manipulating SharePoint with Client-Side JavaScriptPower to the People:  Manipulating SharePoint with Client-Side JavaScript
Power to the People: Manipulating SharePoint with Client-Side JavaScriptPeterBrunone
 
Web Socket
Web SocketWeb Socket
Web SocketJack Bui
 
SPS Chevy Chase - Build It and They Will Come: Sharepoint 2013 User Adoption
SPS Chevy Chase - Build It and They Will Come: Sharepoint 2013 User AdoptionSPS Chevy Chase - Build It and They Will Come: Sharepoint 2013 User Adoption
SPS Chevy Chase - Build It and They Will Come: Sharepoint 2013 User AdoptionStacy Deere
 
MyIX Updates
MyIX UpdatesMyIX Updates
MyIX UpdatesMyNOG
 
Integrating volunteers and Experts
Integrating volunteers and ExpertsIntegrating volunteers and Experts
Integrating volunteers and Expertsdejp3
 
Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016
Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016
Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016Phil Leggetter
 
Introduction to WebSockets
Introduction to WebSocketsIntroduction to WebSockets
Introduction to WebSocketsGunnar Hillert
 
CCNA RSE Routing concept
CCNA RSE Routing conceptCCNA RSE Routing concept
CCNA RSE Routing conceptnewbie2019
 

Similar to Deep Dive into ASP.NET Routing (20)

Who's Watching, by Geoff Huston [APNIC 38 / Technical Keynote]
Who's Watching, by Geoff Huston [APNIC 38 / Technical Keynote]Who's Watching, by Geoff Huston [APNIC 38 / Technical Keynote]
Who's Watching, by Geoff Huston [APNIC 38 / Technical Keynote]
 
Mulesoft Pune Meetup Deck - Apr 2020
Mulesoft Pune Meetup Deck - Apr 2020Mulesoft Pune Meetup Deck - Apr 2020
Mulesoft Pune Meetup Deck - Apr 2020
 
VTA Hack My Ride Lightning Talks
VTA Hack My Ride Lightning TalksVTA Hack My Ride Lightning Talks
VTA Hack My Ride Lightning Talks
 
Jinchao demo v3
Jinchao demo v3Jinchao demo v3
Jinchao demo v3
 
Jetstream: Adding Cloud-based Computing to the National Cyberinfrastructure
Jetstream: Adding Cloud-based Computing to the National CyberinfrastructureJetstream: Adding Cloud-based Computing to the National Cyberinfrastructure
Jetstream: Adding Cloud-based Computing to the National Cyberinfrastructure
 
Slides internet technology
Slides internet technologySlides internet technology
Slides internet technology
 
Jetstream - Adding Cloud-based Computing to the National Cyberinfrastructure
Jetstream - Adding Cloud-based Computing to the National CyberinfrastructureJetstream - Adding Cloud-based Computing to the National Cyberinfrastructure
Jetstream - Adding Cloud-based Computing to the National Cyberinfrastructure
 
Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)
Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)
Building Real Time Web Applications with SignalR (NoVA Code Camp 2015)
 
Java socket programming
Java socket programmingJava socket programming
Java socket programming
 
Power to the People: Manipulating SharePoint with Client-Side JavaScript
Power to the People:  Manipulating SharePoint with Client-Side JavaScriptPower to the People:  Manipulating SharePoint with Client-Side JavaScript
Power to the People: Manipulating SharePoint with Client-Side JavaScript
 
Web Socket
Web SocketWeb Socket
Web Socket
 
Scalable IoT platform
Scalable IoT platformScalable IoT platform
Scalable IoT platform
 
SPS Chevy Chase - Build It and They Will Come: Sharepoint 2013 User Adoption
SPS Chevy Chase - Build It and They Will Come: Sharepoint 2013 User AdoptionSPS Chevy Chase - Build It and They Will Come: Sharepoint 2013 User Adoption
SPS Chevy Chase - Build It and They Will Come: Sharepoint 2013 User Adoption
 
MyIX Updates
MyIX UpdatesMyIX Updates
MyIX Updates
 
Sqlviking
SqlvikingSqlviking
Sqlviking
 
Integrating volunteers and Experts
Integrating volunteers and ExpertsIntegrating volunteers and Experts
Integrating volunteers and Experts
 
Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016
Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016
Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016
 
Introduction to WebSockets
Introduction to WebSocketsIntroduction to WebSockets
Introduction to WebSockets
 
Windows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside worldWindows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside world
 
CCNA RSE Routing concept
CCNA RSE Routing conceptCCNA RSE Routing concept
CCNA RSE Routing concept
 

More from Stacy Vicknair

Systems Thinking for Engineering Leaders.pdf
Systems Thinking for Engineering Leaders.pdfSystems Thinking for Engineering Leaders.pdf
Systems Thinking for Engineering Leaders.pdfStacy Vicknair
 
The Game Master's Guide to People Management
The Game Master's Guide to People ManagementThe Game Master's Guide to People Management
The Game Master's Guide to People ManagementStacy Vicknair
 
Maintainable Documentation with Sphinx
Maintainable Documentation with SphinxMaintainable Documentation with Sphinx
Maintainable Documentation with SphinxStacy Vicknair
 
Building Faster Horses: Taking Over An Existing Software Product
Building Faster Horses: Taking Over An Existing Software ProductBuilding Faster Horses: Taking Over An Existing Software Product
Building Faster Horses: Taking Over An Existing Software ProductStacy Vicknair
 
ASP.NET Routing Deep Dive
ASP.NET Routing Deep DiveASP.NET Routing Deep Dive
ASP.NET Routing Deep DiveStacy Vicknair
 
Asp.net routing with mvc deep dive
Asp.net routing with mvc deep diveAsp.net routing with mvc deep dive
Asp.net routing with mvc deep diveStacy Vicknair
 

More from Stacy Vicknair (8)

Systems Thinking for Engineering Leaders.pdf
Systems Thinking for Engineering Leaders.pdfSystems Thinking for Engineering Leaders.pdf
Systems Thinking for Engineering Leaders.pdf
 
The Game Master's Guide to People Management
The Game Master's Guide to People ManagementThe Game Master's Guide to People Management
The Game Master's Guide to People Management
 
Maintainable Documentation with Sphinx
Maintainable Documentation with SphinxMaintainable Documentation with Sphinx
Maintainable Documentation with Sphinx
 
Building Faster Horses: Taking Over An Existing Software Product
Building Faster Horses: Taking Over An Existing Software ProductBuilding Faster Horses: Taking Over An Existing Software Product
Building Faster Horses: Taking Over An Existing Software Product
 
Git'in in 15
Git'in in 15Git'in in 15
Git'in in 15
 
Git'in on Windows
Git'in on WindowsGit'in on Windows
Git'in on Windows
 
ASP.NET Routing Deep Dive
ASP.NET Routing Deep DiveASP.NET Routing Deep Dive
ASP.NET Routing Deep Dive
 
Asp.net routing with mvc deep dive
Asp.net routing with mvc deep diveAsp.net routing with mvc deep dive
Asp.net routing with mvc deep dive
 

Recently uploaded

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Recently uploaded (20)

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

Deep Dive into ASP.NET Routing

  • 1. ASP.NET ROUTING DEEP DIVE Stacy Vicknair Sparkhound 0
  • 2. Welcome to Houston TechFest Thank you for being a part of the 7th Annual Houston TechFest! • Please turn off all electronic devices or set them to vibrate. • If you must take a phone call, please do so in the lobby so as not to disturb others. • Thanks to our Diamond Sponsors: 1
  • 3. Information • Speaker presentation slides will be available at www.houstontechfest.org within a week • Don’t forget to complete the Bingo card to be eligible for door prizes 2
  • 4. ABOUT ME Stacy Vicknair, MVP Senior Development Consultant Blog http://www.wtfnext.com Toastmasters http://www.toastmasters.org http://www.batonrougespeaks.com Twitter: @svickn Email: stacy.vicknair@sparkhound.com
  • 5. “BE A HERO. GROW A BEARD.” The Sparkhound Foundation is sponsoring the growth of facial hair to raise Prostate Cancer Awareness. Through Septembeard we will raise funds for the research and treatment of prostate cancer. Want to join us? Learn more at Septembeard.org.
  • 6. Agenda • • • • • • What Is Routing? Out of the Box ASP.NET MVC Routing Customizing ASP.NET MVC Routing Unit Testing ASP.NET MVC Routes Routing In ASP.NET WebForms Helpful Links 5
  • 7. What is ASP.NET Routing? “ASP.NET routing enables you to use URLs that do not have to map to specific files in a Web site.” - http://msdn.microsoft.com/en-us/library/cc668201.aspx www.mysite.com/categories.aspx?categoryName=sports www.mysite.com/categories/sports 6 6
  • 10. ASP.NET MVC Routing (System.Web.Mvc) 9
  • 11. Out of the box MVC Routing • Routes.IgnoreRoute() – System.Web.Routing.StopRoutingHandler • Routes.MapRoute() – System.Web.Mvc.RouteCollectionExtensions – Parameters 1 0 • string name – “MyUniqueName” • string url – “{controller}/{action}/{id}” • Object defaults new { controller = "Home", action = "Index”} • Object constraints – new {id = “[0-9]+”} • string[] namespaces - new[] { "MyProject.MyControllers"} 10
  • 12. DEMO – Out of the box MVC Routing 1 1 11
  • 13. Customizing ASP.NET MVC Routing • Three main areas for routing customization – RouteConstraints • Implementing constraints that require more logic than RegEx • Created by implementing System.Web.Routing.IRouteConstraint – Routes • Allow for control over how route data is parsed or route paths are determined • Created by subclassing System.Web.Routing.RouteBase • Default is Route ex. RouteCollection.Add(new Route(…)) – RouteHandlers • Allow for preprocessing before default RouteHandler behavior – ex. RouteData modifications 12
  • 14. DEMO – RouteConstraints and Routes 1 3 13
  • 15. Unit Testing Routes • Use RouteTable.Routes.GetRouteData() – Requires mocked HttpContext (to provide the URL) • Enumerate over RouteData to ensure the proper information is returned • Alternative is MVCContrib – string.ShouldMapTo<T>(c => c.Action()); – Not “officially” ported to MVC4 by Ndepend yet. • Search NuGet for MvcContrib.Mvc4 to find a port 14
  • 16. DEMO – Unit Testing with Routes 1 5 15
  • 17. Adding Routing to ASP.NET WebForms • In the Global.asax, add a reference to System.Web.Routing • Add routes via RouteTable.Routes.MapPageRoute() • Update links to use routes – RouteUrl – GetVirtualPath • Get Routing Data – RouteValue – RouteData.Values[] 16
  • 18. DEMO – Routes in ASP.NET WebForms 1 7 17
  • 19. Agenda • • • • • • What Is Routing? Out of the Box ASP.NET MVC Routing Customizing ASP.NET MVC Routing Unit Testing ASP.NET MVC Routes Routing In ASP.NET WebForms Helpful Links 18
  • 20. Helpful Links THE MOST IMPORTANT LINK I COULD EVER TELL YOU: http://aspnetwebstack.codeplex.com/ http://mvccontrib.codeplex.com/ - MVCContrib http://msdn.microsoft.com/en-us/library/dd329551.aspx - Webforms Google or Bing: ASP.NET Routing Slides / Code will be available at http://www.wtfnext.com References: http://www.15seconds.com/Issue/020417.htm http://msdn.microsoft.com/en-us/library/cc668201.aspx http://blogs.msdn.com/b/alikl/archive/2009/04/02/how-asp-net-mvc-works-for-aspiring-architects-2.aspx http://blog.didsburydesign.com/2010/02/how-to-allow-hyphens-in-urls-using-asp-net-mvc-2/ http://stackoverflow.com/questions/1107507/asp-net-mvc-custom-route-handler-constraint http://haacked.com/archive/2007/12/17/testing-routes-in-asp.net-mvc.aspx 19
  • 21. Please Leave Feedback During Q&A If you leave session feedback and provide contact information, you will be qualified for a prize Scan the QR code to the right or go to bit.ly/htf130202 20

Editor's Notes

  1. Why are we doing this? In honor of the Sparkies and Sparkie family members who have (or continue to fight) fought prostate cancerBackground:- The Sparkhound Foundation is our non-profit charitable giving organization- Prostate cancer is the second leading cause of death in American men.
  2. Why are we doing this? In honor of the Sparkies and Sparkie family members who have (or continue to fight) fought prostate cancerBackground:- The Sparkhound Foundation is our non-profit charitable giving organization- Prostate cancer is the second leading cause of death in American men.