mvc

Routing System Assembly Location in MVC

Routing System Assembly Location in MVC,Routing System ,System.Web.MVC, MVC project,Controllers/Actions in MVC Framework,Global.asax ,Example of Global.axas routers method used in MVC.NET,ASP.NET application
Share it:
Routing System Assembly Location in MVC
google 

Routing System is commonly used for MVC. However, it was designed to be used with standard ASP.NET projects or WebForms. It is the main reason for Routing System Assembly to be located in System. Web and not strictly in System.Web.MVC. Assembly name that is being added to your MVC project, when you create it for the first time, is called System.Web.Routing. However, the System. The web is enough for Routing System to work with your project.

Routing applies not just to MVC and WebForms but to all other aspects of the ASP.NET platform. It is designed to be versatile in what it can do. Routing System is designed to be generic and it does not aware of Controllers/Actions in MVC Framework. It is designed to pass segments of URL to the Request pipeline. Any ASP.NET application can use this request pipeline for intended purposes.

Routers generally defined in Global.asax file and .NET MVC Project template set up this file with Routers entries for you by default.


Example of Global.axas routers method used in MVC.NET

 public static void RegisterRoutes(RouteCollection routes)

        {

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(

                "Default", // Route name

                "{controller}/{action}/{id}", // URL with parameters

                new { controller = "User", action = "Index", id = UrlParameter.Optional } // Parameter defaults

            );

        }
Another way of setting up Routing for ASP.NET application other than MVC is as follows:


public static void RegisterRoutes(RouteCollection routes)

        {

            Route myRoute = new Route("{controller}/{action}", new MvcRouteHandler());

            routes.Add("MyRoute", myRoute);
        }

Actually, Routers are set up in Global.asax.cs file and not purely in Global.asax. However, it is common to refer to Routers being part of the Global.asax file.
Share it:

mvc

Post A Comment:

0 comments: