What's the difference between RouteCollection and Route Table
The RouteTable
is a class that stores the URL routes for your application.
A RouteCollection
provides a collection of route information to be used when mapping a URI to a controller action.
The RouteTable
contains a property called Routes
that will return a RouteCollection
. The RouteTable
uses a RouteCollection
in order to store all the URL routing information it needs to accurately direct URI's to the correct controller action.
In your global.asax you will register the routes that will map to various controller actions by specifying the following:
/// <summary>
/// Executed when the application starts.
/// </summary>
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
Then a route will be added to the RouteCollection
in the following way:
/// <summary>
/// Registers the routes used by the application.
/// </summary>
/// <param name="routes">Routes to register.</param>
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Error",
"Error",
new { controller = "Error", action = "Error" });
}
This shows how the actual route information is stored in a RouteCollection
, which in turn is referenced via the RouteTable
.
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
Can you tell the difference between RouteCollection and Route Table?
I tried a lot to search at Google. But could not found any references.
-
Sajeetharan about 6 yearshow can i import RouteTable in .net standard 2 project