使用默认文档进行路由

时间:2011-03-13 18:00:39

标签: model-view-controller routing

我真的很难理解路由。这可能是之前被问过但我找不到或没有问正确的方法......

我正在移植现有的经典asp网站,并首先添加管理信息中心。我需要的是当用户只是输入站点名称时,默认文档(default.asp)被加载,但是如果他们进入{site} / Admin,则路由接管。我的默认路由控制器名为“AdminController”,我的项目设置为在/ Admin中启动。除非我回到新项目附带的基本默认路由,否则其他任何操作都无效。

欲望:

  1. {site} - > {站点} /default.asp
  2. {site} / Admin - >管理/索引操作
  3. {site} / Admin / Shops - >商店/索引行动
  4. {site} / Admin / Shops / Edit / {id} - >商店/编辑(id)行动
  5. 这是我的路线,我被困在某处:

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.RouteExistingFiles = true;
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
            routes.MapRoute(
                "EditShop", // Route name
                "Shops/Edit/{slug}", // URL with parameters
                new
                {
                    controller = "Shops",
                    action = "Edit",
                    slug = ""
                } // Parameter defaults
            );
    
            routes.MapRoute(
                "Shops", // Route name
                "Admin/Shops/", // URL with parameters
                new
                {
                    controller = "Shops",
                    action = "Index"
                } // Parameter defaults
            );
    
            // default route for this app
            routes.MapRoute(
                "Admin", // Route name
                "Admin/", // URL with parameters
                new { controller = "Admin", action = "Index" } // Parameter defaults
            );
    
           //  default route for this app (this works for all cases except default.asp)
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Admin", action = "Index", id = UrlParameter.Optional } 
            );
    
            routes.MapRoute("NothingMatched", "{*url}",
                            new {controller = "Error", action = "Http404"});
        }
    

2 个答案:

答案 0 :(得分:0)

我看到你将EditShop映射到商店/编辑。这可能应该映射到Admin / Shops / Edit以实现您想要的效果。我没有看到其他路线有任何问题,但我可能是错的。

答案 1 :(得分:0)

有几篇帖子回答了这个问题such as this one