SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Ähnlich wie 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
 
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
 
Web-01-HTTP.pptx
Web-01-HTTP.pptxWeb-01-HTTP.pptx
Web-01-HTTP.pptxAliZaib71
 

Ähnlich wie 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
 
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
 
Web-01-HTTP.pptx
Web-01-HTTP.pptxWeb-01-HTTP.pptx
Web-01-HTTP.pptx
 

Mehr von 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
 

Mehr von 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
 

Kürzlich hochgeladen

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
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...apidays
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
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 organizationRadu Cotescu
 
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.pptxHampshireHUG
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
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 textsMaria Levchenko
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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 DevelopmentsTrustArc
 
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 2024The Digital Insurer
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
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 Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
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
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

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

Hinweis der Redaktion

  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.