Routing in ASP.NET MVC

In today's modern web application each and every thing is important including request URL pattern of the application to make application more traffic driven and user friendly. In earlier ASP.NET application all the user request are mapped with physical file location that is with .aspx pages. These types of URL pattern are won't be customized to make it user, SEO friendly and most of the time in ASP.NET application to overcome these URL drawback URL rewriting technique is used, But still it unable to fulfill the expected requirement.
In ASP.NET MVC, URL pattern is completely different as compare to the ASP.NET application URL pattern, So lets learn about the ASP.NET MVC routing.

What is routing in ASP.NET MVC ?
Routing is the concept in ASP.NET MVC which is used to define the URL pattern for the ASP.NET MVC application incoming user request.
There are two types of routing supported by ASP.NET MVC
  • Conventional based routing 
  • Attribute routing
Conventional Routing
The default routing in ASP.NET MVC is a conventional routing which is get added in RouteConfig.cs file when we create ASP.NET MVC application, These type of routing defined in RouteConfig.cs file .

The following is the default routing

Suppose we have Employee method in ASP.NET MVC application and we want to define the URL pattern that how this method can be called by end user then routing pattern can be defined as in the following

Attribute Routing
The routing which is defined on controller or action level is called as attribute routing . These type of routing is only supports in  MVC 5 version onward
I hope from preceding brief explanation you have learned about the ASP.NET MVC routing, In my next article we will learn each of the routing in details with real time examples.
    The preceding is the example of attribute routing which can be enabled in RouteConfig.cs by calling MapMvcAttributeRoutes method of RouteCollection class
    
    Key Points
    • RouteCollection class is used for routing which uses the System.Web.Routing namespace
    • ASP.NET MVC 5 supports two types of routing that is conventional and attribute routing
    • Conventional based is the default routing in ASP.NET MVC 
    • Attribute routing can be defined on controller as well as action level
    • All routes should be registered into the Global.asax file .
    • Every ASP.NET MVC application must have at least one routing defined
    • We can define multiple routing in single application in this case it executed sequence wise as it defined.
    • If we are defining two route templates then the route name must be different across the application level
    Summary
    I hope, this article is useful for all the readers. If you have any suggestions, please contact me. In my next article we will learn real time example of conventional and attribute routing.

    Don't Forget To  

    Post a Comment

    www.CodeNirvana.in

    Protected by Copyscape Online Copyright Protection
    Copyright © Compile Mode