Skip to main content

Posts

Showing posts with the label What Is Routing?

What Is Attribute based Routing?

What Is Attribute based Routing? MVC 5 supports a new type of routing  that called attribute routing. It used to define routes. Enable Attribute Routing - If you want to use Attribute Routing, you must enable it by calling MapMvcAttributeRoutes on the RouteCollection. public class RouteConfig {     public static void RegisterRoutes ( RouteCollection routes )     {         routes . IgnoreRoute ( "{resource}.axd/{*pathInfo}" );                //Enables Attribute Routing         routes . MapMvcAttributeRoutes ();     } } Defining a Route - A route attribute has to be defined on top of an action method or on the top of a controller. The Example looks like, public class HomeController : BaseController {   [ Route ( "User/GetUsers" )]   public Act...

What Is ASP.NET MVC Routing ?

What Is Routing? The MCV Routing is a pattern matching system that matches  all browser’s incoming requests  to the  registered URL patterns  residing in the  RouteTable . When the MVC application starts, it registers  patterns  to the  RouteTable  to tell the  routing engine  to give a  response to the requests  that  match these patterns . An application has only one  RouteTable . Routes can be configured in  RouteConfig  class. Multiple custom routes can also be configured. The route must be registered in  Application_Start  event in the  Global.ascx.cs  file. Each MVC application has default routing for the default  HomeController . We can also set custom routing and the  RouteConfig  class. The three segments that is important for routing is  - {controller}/{action}/{id} RouteConfig class An example for Register Routes - public class ...