Exemple #1
0
        public static void RegisterRoutes( RouteCollection routes )
        {
            if (routes == null) throw new ArgumentNullException( "routes" );

            routes.Clear();

            // Turns off the unnecessary file exists check
            routes.RouteExistingFiles = true;

            // Ignore text, html, files.
            routes.IgnoreRoute( "{file}.txt" );
            routes.IgnoreRoute( "{file}.htm" );
            routes.IgnoreRoute( "{file}.html" );

            // Ignore the assets directory which contains images, js, css & html
            routes.IgnoreRoute( "assets/{*pathInfo}" );

            // Ignore axd files such as assest, image, sitemap etc
            routes.IgnoreRoute( "{resource}.axd/{*pathInfo}" );

            //Exclude favicon (google toolbar request gif file as fav icon which is weird)
            routes.IgnoreRoute( "{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" } );

            //// Routing config for the admin area
            //routes.CreateArea( 
            //    "admin", 
            //    "Jumblist.Website.Areas.Admin.Controllers",
            //    routes.MapRoute( 
            //        null, 
            //        "admin/{controller}/{action}/{id}", 
            //        new { controller = "Home", action = "Index", id = "" } 
            //    )
            //);

            //// Routing config for the root (public) area
            //routes.CreateArea(
            //    "root",
            //    "Jumblist.Website.Controllers",
            //    routes.MapRoute(
            //        null,
            //        "{controller}/{action}/{id}",
            //        new { controller = "Home", action = "Index", id = "" }
            //    )
            //);

            AreaRegistration.RegisterAllAreas();

            routes.JumblistMapRoute(
                "Post-Detail",                                              // Route name
                "post/{id}/{name}",                           // URL with parameters
                new { controller = "Posts", action = "Detail", id = "", name = "" },  // Parameter defaults
                new string[] { "Jumblist.Website.Controllers" }
            );

            routes.JumblistMapRoute(
                "XMLSitemap",                                              // Route name
                "sitemap.xml",                           // URL with parameters
                new { controller = "Posts", action = "XmlSiteMap" },  // Parameter defaults
                new string[] { "Jumblist.Website.Controllers" }
            );

            routes.JumblistMapRoute(
                "Rss-WithCategory",                                              // Route name
                "{controller}/{rssactionname}/{rssactionid}/{rssactioncategory}/rss",                           // URL with parameters
                new { controller = "Posts", action = "Rss", rssactionname = "Index" },  // Parameter defaults
                new string[] { "Jumblist.Website.Controllers" }
            );

            routes.JumblistMapRoute(
                "Rss-WithAction",                                              // Route name
                "{controller}/{rssactionname}/{rssactionid}/rss",                           // URL with parameters
                new { controller = "Posts", action = "Rss", rssactionname = "Index" },  // Parameter defaults
                new string[] { "Jumblist.Website.Controllers" }
            );

            routes.JumblistMapRoute(
                "Rss",                                              // Route name
                "{controller}/rss",                           // URL with parameters
                new { controller = "Posts", action = "Rss", rssactionname = "Index" },  // Parameter defaults
                new string[] { "Jumblist.Website.Controllers" }
            );

            routes.JumblistMapRoute(
                "Category",                                              // Route name
                "{controller}/{action}/{id}/{category}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional, category = UrlParameter.Optional },  // Parameter defaults
                new string[] { "Jumblist.Website.Controllers" }
            );

            routes.JumblistMapRoute(
                "Default",                                              // Route name
                "{controller}/{action}/{id}",                           // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional },  // Parameter defaults
                new string[] { "Jumblist.Website.Controllers" }
            );

            //routes.Add(
            //    new JumblistRoute(
            //        "{controller}/{action}/{id}",
            //        new RouteValueDictionary( new { 
            //            controller = "Home", 
            //            action = "Index", 
            //            id = UrlParameter.Optional 
            //        } ),
            //        new MvcRouteHandler()
            //    )
            //);
        }