![]() |
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.
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);
}
Post A Comment:
0 comments: