What is the difference between RouteCollection and Route Table

Can you talk about the difference between a RouteCollection and a route table?

I tried a lot to search on Google. But did not find links.

+4
source share
1 answer

RouteTable is a class that stores URL routes for your application.

A RouteCollection provides a collection of route information that will be used when mapping URIs to controller actions.

RouteTable contains a Routes property that will return a RouteCollection . RouteTable uses RouteCollection to store all the URL routing information needed to accurately tell the URI the correct controller action.

In your global.asax, you will register routes that will be mapped to various controller actions by specifying the following:

 /// <summary> /// Executed when the application starts. /// </summary> protected void Application_Start() { RegisterRoutes(RouteTable.Routes); } 

Then the route will be added to the RouteCollection as follows:

 /// <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 the RouteCollection , which, in turn, is referenced via RouteTable .

+6
source

Source: https://habr.com/ru/post/1482152/


All Articles