SlideShare una empresa de Scribd logo
1 de 34
Emad Alashi
ASP.NET/IIS MVP
Jordev
Readify
www.DotNetArabi.com
www.EmadAshi.com
@emadashi
URL Routing & MVC
ALL YOUR URL ARE BELONG TO YOU!
Agenda
• Why understanding Routing is important
• What is Routing?
• How it works
• How to test it
• Best Some practices
Why understanding Routing
• The entry to your web app
• HyperTextTransferProtol
• Strongly relates to Binding
• Never stay in doubt
What is URL Routing
History
/store/products.aspx?key=value
                                     Store       Page life cycle




                                                  QueryString*“..”+
                                 Products.aspx
Handlers
Store/products/apples


•    Parse
•    Extract variables         OtherHttpHandler

•    Route to Handler    URL

                               MVCHttpHandler
Handlers
 Options?
• Rigid (absolute string comparison):
   e.g. “http://store/products/view” ===> invoke method “view” in class “products”


• Pattern base:
   1.   http://store/{classX}/{methodY} ===> use MvcHttpHandler => Invoke method “Y” in class “X”
   2.   http://p/sub}/{module} ===> use MagicHttpHandler => invoke crazy code
Priority
We have to choose between patterns!
           routes.MapRoute(
               name: "Default",
               url: "{controller}/{action}/",
               defaults: new { controller = "Home", action = "Index"}
           );
           routes.MapRoute(
               name: "My2ndRoute",
               url: "special{awesome}Pattern/{anotherVariable}",
               defaults: new { awesome = "magic"}
           );
How URL Routing
works
Segmentation
        http://store.com/home/index

                   First segment   Second segment
Static words
                   “,controller- /,action-”
                       “home/index”
                     “anything/willdo”
           =============================
               “abc,controller- /     ,action-”
                 “abchome / whatever”
                   ==================
               “abc,controller- /     ,action-”
                   “home / whatever”
RouteData.Values
  “,controller}/{action-/,id-”
  “product/index/3”



                                 Variable     value
                                 controller   Product
                                 action       Index
                                 id           3
Defaults
Or Defaults:                                        Variable     Value
     “product/index”                                controller   Product

?                                                   action       Index
     routes.MapRoute(                               id
                                                    Id           !
                                                                 3

               name: "Default",

               url: "{controller}/{action}/{id}",

               defaults: new { id=3 }

         );
UrlParameter.Optional
 routes.MapRoute(

 name: "Default",

 url: "{controller}/{action}/{id}",                          Variable     value
 defaults: new {action = "Index“, id=UrlParameter.Optinal}   controller   Product

             );                                              action       Index
                                                             id           3
• Supplied: “product/index/3”
• Not supplied:                                              Variable     value
       “product/index”                                       controller   Product
                                                             action       index
No excessive number of segments
          “,controller-/,action-/,id-”
          “products/oranges/edit/3”
Unless:
          “,controller}/{action}/{id}/{*catchall-”
          “product/oranges/edit/3/something’
                                                     Variable     value
                                                     controller   Product
                                                     action       Index
                                                     id           edit
                                                     Catchall     3/something
Constraints
 1.   Regular Expressions:
      routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", …

                    constraints: new { controller = "^H.*" }          );
 2.   Specific values:
                    constraints: new { action = "^Index$|^About$*" }
 3.   HTTP methods:
                    constraints: new { httpMethod= new HttpMethodConstraint("GET") }
 4.   Custom constraints:

      bool IRouteConstraint.Match(HttpContextBase, Route, stringParameterName, RouteValueDictionary,
      RouteDireciont)
Debug Routes
Notes (Incoming)
• Reserved custom variables: “controller, action, area”
• routes.RouteExistingFiles = true;
• routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
• Last segment includes the QueryString
How Routing works
   (Outgoing)
Helpers
1.   Html.ActionLink(text, nameOfAction, nameOfController, RouteValues, HtmlAttributes)
2.   Url.Action(text, nameOfAction, nameOfController, RouteValues)
3.   @Html.RouteLink(text, RouteValues, HtmlAttributes)
4.   Url.RouteLink(text, AnonymouseTypeValues)


•    You can use Route name
Rules
1.   All variables should have values: “,controller-/,action-/,id-”
     a)   Supplied
     b)   Current request
     c)   Default values

2.   Should not dis-agree with default-only variables:
     routes.MapRoute("MyRoute", "{controller}/{action}", new { myVar = "true" });

3.   Satisfy constraints
Notes (Outgoing)
• Tricky: Reuse values of the current request URL:
   url: "{controller}/{action}/{id}/{forth}",

                   defaults: new { controller = "Home", action = "Index", id = 3, forth=8},
------------
                  @Html.ActionLink("this is the link", "Index", new {id=5 });
                  @Html.ActionLink("this is the link", "Index", new {forth=8 });

• Url’s generated will try to produce the shortest url
Areas
Areas
public class AdminAreaRegistration : AreaRegistration {
       public override string AreaName         { get   {
                return "Admin";     }    }
       public override void RegisterArea(AreaRegistrationContext context)
       {
           context.MapRoute(
                "Admin_default",
                "Admin/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional }
           );
       }
   }
Areas
AreaRegistration.RegisterAllAreas();


RouteConfig.RegisterRoutes(RouteTable.Routes);
Unit-Testing Routes
Unit-Testing Routes (Incoming)
What do we want to test?


That the url patterns we want to support in our web app would populate the RouteData variables
as expected.
Unit-Testing Routes (Incoming)
• Incoming:
   •   HttpRequestBase
   •   HttpContextBase
   •   HttpResponseBase

• Outcoing:
   •   +
   •   UrlHelper
Unit-Testing Routes (Incoming)


                Demo
Unit-Testing Routes (Incoming)

                                     MvcContrib
                             http://mvccontrib.codeplex.com/


"~/Products/View/44/offer".ShouldMapTo<ProductsController>(action => action.View(44, “offer"));
Design Guidelines
• Content vs Implementation
• Human friendly: content titles vs id’s
• Hackable
• Sense of hierarchy
• Static strings at the beggning of routes
• Dash instead of underscore
• Not too long
• Avoid complexity
• Be consistent
ASP.NET

       It’s all open source!
     http://aspnetwebstack.codeplex.com/
Q&A


      www.emadashi.com
         @EmadAshi

Más contenido relacionado

La actualidad más candente

JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events WebStackAcademy
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)Brian Swartzfager
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsRob O'Doherty
 
Nodejs functions & modules
Nodejs functions & modulesNodejs functions & modules
Nodejs functions & modulesmonikadeshmane
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/ServletSunil OS
 
Asp.net MVC training session
Asp.net MVC training sessionAsp.net MVC training session
Asp.net MVC training sessionHrichi Mohamed
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptWalid Ashraf
 
How to implement internationalization (i18n) in angular application(multiple ...
How to implement internationalization (i18n) in angular application(multiple ...How to implement internationalization (i18n) in angular application(multiple ...
How to implement internationalization (i18n) in angular application(multiple ...Katy Slemon
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentationivpol
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsDinesh U
 
Document object model
Document object modelDocument object model
Document object modelAmit kumar
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC PresentationVolkan Uzun
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming WebStackAcademy
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS DirectivesEyal Vardi
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_contentNAVEENSAGGAM1
 

La actualidad más candente (20)

JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
 
AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)AngularJS $http Interceptors (Explanation and Examples)
AngularJS $http Interceptors (Explanation and Examples)
 
RESTful Web API
RESTful Web APIRESTful Web API
RESTful Web API
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Nodejs functions & modules
Nodejs functions & modulesNodejs functions & modules
Nodejs functions & modules
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Asp.net MVC training session
Asp.net MVC training sessionAsp.net MVC training session
Asp.net MVC training session
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to JavascriptLab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
 
Jsp chapter 1
Jsp chapter 1Jsp chapter 1
Jsp chapter 1
 
How to implement internationalization (i18n) in angular application(multiple ...
How to implement internationalization (i18n) in angular application(multiple ...How to implement internationalization (i18n) in angular application(multiple ...
How to implement internationalization (i18n) in angular application(multiple ...
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Document object model
Document object modelDocument object model
Document object model
 
ASP.NET MVC Presentation
ASP.NET MVC PresentationASP.NET MVC Presentation
ASP.NET MVC Presentation
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming  Angular - Chapter 2 - TypeScript Programming
Angular - Chapter 2 - TypeScript Programming
 
Basic Python Django
Basic Python DjangoBasic Python Django
Basic Python Django
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_content
 
React/Redux
React/ReduxReact/Redux
React/Redux
 

Similar a ASP.NET Routing & MVC

Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
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-rsSagara Gunathunga
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_HourDilip Patel
 
Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4soelinn
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneRafael Felix da Silva
 
Asp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design PatternAsp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design Patternmaddinapudi
 
cake phptutorial
cake phptutorialcake phptutorial
cake phptutorialice27
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Patterngoodfriday
 
SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015Pushkar Chivate
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js FundamentalsMark
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsFrancois Zaninotto
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVCRichard Paul
 
Resource and view
Resource and viewResource and view
Resource and viewPapp Laszlo
 
Rails vs Web2py
Rails vs Web2pyRails vs Web2py
Rails vs Web2pyjonromero
 

Similar a ASP.NET Routing & MVC (20)

ASP .net MVC
ASP .net MVCASP .net MVC
ASP .net MVC
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Struts2 - 101
Struts2 - 101Struts2 - 101
Struts2 - 101
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 
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
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4Retrofit Web Forms with MVC & T4
Retrofit Web Forms with MVC & T4
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
 
Asp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design PatternAsp.Net MVC Framework Design Pattern
Asp.Net MVC Framework Design Pattern
 
cake phptutorial
cake phptutorialcake phptutorial
cake phptutorial
 
Spring MVC Basics
Spring MVC BasicsSpring MVC Basics
Spring MVC Basics
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
 
AngularJs-training
AngularJs-trainingAngularJs-training
AngularJs-training
 
SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
Introduction to Spring MVC
Introduction to Spring MVCIntroduction to Spring MVC
Introduction to Spring MVC
 
Node.js and Parse
Node.js and ParseNode.js and Parse
Node.js and Parse
 
Resource and view
Resource and viewResource and view
Resource and view
 
Rails vs Web2py
Rails vs Web2pyRails vs Web2py
Rails vs Web2py
 

Más de Emad Alashi

RBAC in Azure Kubernetes Service AKS
RBAC in Azure Kubernetes Service AKSRBAC in Azure Kubernetes Service AKS
RBAC in Azure Kubernetes Service AKSEmad Alashi
 
Am I a Good Developer
Am I a Good DeveloperAm I a Good Developer
Am I a Good DeveloperEmad Alashi
 
Basic Intro to WinDbg
Basic Intro to WinDbgBasic Intro to WinDbg
Basic Intro to WinDbgEmad Alashi
 
Acquiring knowledge
Acquiring knowledgeAcquiring knowledge
Acquiring knowledgeEmad Alashi
 
Owin, Katana, and Helios
Owin, Katana, and HeliosOwin, Katana, and Helios
Owin, Katana, and HeliosEmad Alashi
 
OAuth in the new .NET world (OWIN)
OAuth in the new .NET world (OWIN)OAuth in the new .NET world (OWIN)
OAuth in the new .NET world (OWIN)Emad Alashi
 
Software Life Cycle, Humans & Code
Software Life Cycle, Humans & CodeSoftware Life Cycle, Humans & Code
Software Life Cycle, Humans & CodeEmad Alashi
 
ASP.NET MVC One Step Deeper
ASP.NET MVC One Step DeeperASP.NET MVC One Step Deeper
ASP.NET MVC One Step DeeperEmad Alashi
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVCEmad Alashi
 
Communication Skills one To one
Communication Skills one To oneCommunication Skills one To one
Communication Skills one To oneEmad Alashi
 
Introduction To NHibernate
Introduction To NHibernateIntroduction To NHibernate
Introduction To NHibernateEmad Alashi
 

Más de Emad Alashi (12)

RBAC in Azure Kubernetes Service AKS
RBAC in Azure Kubernetes Service AKSRBAC in Azure Kubernetes Service AKS
RBAC in Azure Kubernetes Service AKS
 
Am I a Good Developer
Am I a Good DeveloperAm I a Good Developer
Am I a Good Developer
 
Basic Intro to WinDbg
Basic Intro to WinDbgBasic Intro to WinDbg
Basic Intro to WinDbg
 
Acquiring knowledge
Acquiring knowledgeAcquiring knowledge
Acquiring knowledge
 
Owin, Katana, and Helios
Owin, Katana, and HeliosOwin, Katana, and Helios
Owin, Katana, and Helios
 
OAuth in the new .NET world (OWIN)
OAuth in the new .NET world (OWIN)OAuth in the new .NET world (OWIN)
OAuth in the new .NET world (OWIN)
 
Software Life Cycle, Humans & Code
Software Life Cycle, Humans & CodeSoftware Life Cycle, Humans & Code
Software Life Cycle, Humans & Code
 
HTML5 & IE
HTML5 & IEHTML5 & IE
HTML5 & IE
 
ASP.NET MVC One Step Deeper
ASP.NET MVC One Step DeeperASP.NET MVC One Step Deeper
ASP.NET MVC One Step Deeper
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
Communication Skills one To one
Communication Skills one To oneCommunication Skills one To one
Communication Skills one To one
 
Introduction To NHibernate
Introduction To NHibernateIntroduction To NHibernate
Introduction To NHibernate
 

Último

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
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)Zilliz
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
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 educationjfdjdjcjdnsjd
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
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 DiscoveryTrustArc
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
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...DianaGray10
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

Último (20)

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
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
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
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...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

ASP.NET Routing & MVC

  • 2. URL Routing & MVC ALL YOUR URL ARE BELONG TO YOU!
  • 3. Agenda • Why understanding Routing is important • What is Routing? • How it works • How to test it • Best Some practices
  • 4. Why understanding Routing • The entry to your web app • HyperTextTransferProtol • Strongly relates to Binding • Never stay in doubt
  • 5. What is URL Routing
  • 6. History /store/products.aspx?key=value Store Page life cycle QueryString*“..”+ Products.aspx
  • 7. Handlers Store/products/apples • Parse • Extract variables OtherHttpHandler • Route to Handler URL MVCHttpHandler
  • 8. Handlers Options? • Rigid (absolute string comparison): e.g. “http://store/products/view” ===> invoke method “view” in class “products” • Pattern base: 1. http://store/{classX}/{methodY} ===> use MvcHttpHandler => Invoke method “Y” in class “X” 2. http://p/sub}/{module} ===> use MagicHttpHandler => invoke crazy code
  • 9. Priority We have to choose between patterns! routes.MapRoute( name: "Default", url: "{controller}/{action}/", defaults: new { controller = "Home", action = "Index"} ); routes.MapRoute( name: "My2ndRoute", url: "special{awesome}Pattern/{anotherVariable}", defaults: new { awesome = "magic"} );
  • 11. Segmentation http://store.com/home/index First segment Second segment
  • 12. Static words “,controller- /,action-” “home/index” “anything/willdo” ============================= “abc,controller- / ,action-” “abchome / whatever” ================== “abc,controller- / ,action-” “home / whatever”
  • 13. RouteData.Values “,controller}/{action-/,id-” “product/index/3” Variable value controller Product action Index id 3
  • 14. Defaults Or Defaults: Variable Value “product/index” controller Product ? action Index routes.MapRoute( id Id ! 3 name: "Default", url: "{controller}/{action}/{id}", defaults: new { id=3 } );
  • 15. UrlParameter.Optional routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", Variable value defaults: new {action = "Index“, id=UrlParameter.Optinal} controller Product ); action Index id 3 • Supplied: “product/index/3” • Not supplied: Variable value “product/index” controller Product action index
  • 16. No excessive number of segments “,controller-/,action-/,id-” “products/oranges/edit/3” Unless: “,controller}/{action}/{id}/{*catchall-” “product/oranges/edit/3/something’ Variable value controller Product action Index id edit Catchall 3/something
  • 17. Constraints 1. Regular Expressions: routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", … constraints: new { controller = "^H.*" } ); 2. Specific values: constraints: new { action = "^Index$|^About$*" } 3. HTTP methods: constraints: new { httpMethod= new HttpMethodConstraint("GET") } 4. Custom constraints: bool IRouteConstraint.Match(HttpContextBase, Route, stringParameterName, RouteValueDictionary, RouteDireciont)
  • 19. Notes (Incoming) • Reserved custom variables: “controller, action, area” • routes.RouteExistingFiles = true; • routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); • Last segment includes the QueryString
  • 20. How Routing works (Outgoing)
  • 21. Helpers 1. Html.ActionLink(text, nameOfAction, nameOfController, RouteValues, HtmlAttributes) 2. Url.Action(text, nameOfAction, nameOfController, RouteValues) 3. @Html.RouteLink(text, RouteValues, HtmlAttributes) 4. Url.RouteLink(text, AnonymouseTypeValues) • You can use Route name
  • 22. Rules 1. All variables should have values: “,controller-/,action-/,id-” a) Supplied b) Current request c) Default values 2. Should not dis-agree with default-only variables: routes.MapRoute("MyRoute", "{controller}/{action}", new { myVar = "true" }); 3. Satisfy constraints
  • 23. Notes (Outgoing) • Tricky: Reuse values of the current request URL: url: "{controller}/{action}/{id}/{forth}", defaults: new { controller = "Home", action = "Index", id = 3, forth=8}, ------------ @Html.ActionLink("this is the link", "Index", new {id=5 }); @Html.ActionLink("this is the link", "Index", new {forth=8 }); • Url’s generated will try to produce the shortest url
  • 24. Areas
  • 25. Areas public class AdminAreaRegistration : AreaRegistration { public override string AreaName { get { return "Admin"; } } public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Admin_default", "Admin/{controller}/{action}/{id}", new { action = "Index", id = UrlParameter.Optional } ); } }
  • 28. Unit-Testing Routes (Incoming) What do we want to test? That the url patterns we want to support in our web app would populate the RouteData variables as expected.
  • 29. Unit-Testing Routes (Incoming) • Incoming: • HttpRequestBase • HttpContextBase • HttpResponseBase • Outcoing: • + • UrlHelper
  • 31. Unit-Testing Routes (Incoming) MvcContrib http://mvccontrib.codeplex.com/ "~/Products/View/44/offer".ShouldMapTo<ProductsController>(action => action.View(44, “offer"));
  • 32. Design Guidelines • Content vs Implementation • Human friendly: content titles vs id’s • Hackable • Sense of hierarchy • Static strings at the beggning of routes • Dash instead of underscore • Not too long • Avoid complexity • Be consistent
  • 33. ASP.NET It’s all open source! http://aspnetwebstack.codeplex.com/
  • 34. Q&A www.emadashi.com @EmadAshi

Notas del editor

  1. How many dealt with ASP.NET and HttpHandler
  2. Some historyA page is an HttpHandlerToo rigidBound to a fileThis will not work for MVC, they need to invoke Methods (Actions) in Classes (Controller)So they wanted more flexibilityFile/extension agnosticDifferent handlers (especially they needed to introduce the separation of concerns and invoking controllers on certain points “actions”)
  3. When a request comes to the server, how can the app know how to handle this request?Emphasize on RouteData being passed to the handler
  4. So we could be rigid, or dynamicBut how can we make programmers more interesting and harder? :P
  5. At the startup of the web app
  6. It’s hard to put it in steps since it’s little bit complex and wined together, but we will try
  7. “To be clear, it is not that the value of id is null when nocorresponding segment is supplied; rather, the case is that an id variable is not defined”To distinguish if user sent a value or notSeparation of concerns (defaults in routing?)
  8. Specific values for controllers that might share a URL patternHttp Method has nothing to do with the “post” and “get” action filters
  9. Inspired by RouteDebugger created by Phil Haack
  10. Last segment includes the query string, but it’s up to the IHttpHandler how to handle it
  11. Don’t use fixed URL’s!Routing doesn’t understand what “controller” is or what “action” is.Explain parametersExtra values are added as aquery stringThe Html.Action method uses routing as well, it’s not a direct call
  12. Reuse values of the current request URL only for segment variables that occur earlier in the URL pattern than any parameters that are supplied to the Html.ActionLink method:
  13. Don’t change namespace of controller in an AreaDo use namespace priority for the general controller
  14. Don’t change the order of Area registration to be after Routing
  15. Because it’s the key for the MVCHttpHandlerBy: checking the orderChecking the static stringsChecking constraints if we have them
  16. Before, it was hard to test Routes, now they provided HttpContextBase
  17. Before, it was hard to test Routes, now they provided HttpContextBase
  18. “offer” might be date as wellI am not totally enthusiast since this is not testing Routing only, it intervenes of how binding works
  19. I don’t like best practicesIf external website maybe you want to follow the SEOAvoid complexityContent vs Implementation: REST or Action? if easy go RESTful, no just don’t not too longContent title’s vs ID’s: avoid ID’s in general
  20. For me, sometimes Reflector is easier to navigate