asp.net-mvc - RouteCollection 和路由表有什么区别

标签 asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 asp.net-mvc-2

你能说出 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/

相关文章:

asp.net-mvc-3 - 如果填充了另一个字段,则 MVC 3 字段为必填字段

asp.net-mvc - MVC3 到区域的默认路由不搜索区域内的 View

angularjs - 在 ASP.NET MVC 中使用 Angular data-ng-model 时 HTML 控件无法正常工作

asp.net-mvc - 使用 FormCollection 时,MVC 3 RTM allowedHtml 不起作用

asp.net-mvc - ASP.NET MVC : Restricting access using url

asp.net-mvc - ASP.NET MVC Controller 单元测试令人困惑

jquery - 日期在 jquery 中显示不正确

c# - 将 ASP.NET Identity 集成到现有数据库

c# - IoC 和 "hiding implementation details"

jquery - 更新 'real time'中的验证摘要