你能说出 RouteCollection 和 Route Table 的区别吗?
我尝试了很多在 Google 上进行搜索。但找不到任何引用资料。
最佳答案
RouteTable
是一个存储应用程序 URL 路由的类。
一个 RouteCollection
提供将 URI 映射到 Controller 操作时要使用的路由信息集合。RouteTable
包含一个名为 Routes
的属性这将返回 RouteCollection
. RouteTable
使用 RouteCollection
为了存储所有的 URL 路由信息,它需要准确地将 URI 指向正确的 Controller 操作。
在您的 global.asax 中,您将通过指定以下内容来注册将映射到各种 Controller 操作的路由:
/// <summary>
/// Executed when the application starts.
/// </summary>
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
然后一条路由会被添加到
RouteCollection
通过以下方式:/// <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" });
}
这显示了实际路线信息如何存储在
RouteCollection
中。 ,反过来又通过 RouteTable
引用.
关于asp.net-mvc - RouteCollection 和路由表有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16691566/