我已经得到了这个小组项目,我试图理解并且在路线如何工作方面遇到问题。困扰我的第一件事是为什么在RouteConfig.cs文件中注册了一些路由,而在Global.asax中注册了其他路由?为什么在RouteConfig.cs中使用routes.Add,与routes.MapRoute相比它做了什么?
这里的RouteConfig.cs:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.Add(new LowercaseDashedRoute("{controller}/{action}/{id}",
new RouteValueDictionary(
new { controller = "Home", action = "Index", id = UrlParameter.Optional }),
new DashedRouteHandler()
)
);
}
这是Global.asax:
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute("SpecificRouteforHomeController", "{action}/{id}", new { controller = "Home", action = "Index", id = "" });
// default route any defalt you want
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Services", action = "Index", id = "" });
}