Cake.Web.LegacyRouteConfig.RegisterRoutes C# (CSharp) Метод

RegisterRoutes() публичный статический Метод

public static RegisterRoutes ( RouteCollection routes ) : void
routes RouteCollection
Результат void
        public static void RegisterRoutes(RouteCollection routes)
        {
            // Kind of hackish but will do for now.
            // If this list grows, we might have to look at another solution.
            var lookup = new Dictionary<string, string>()
            {
                {"what-is-cake", "/docs/overview/features"},
                {"getting-started", "/docs/tutorials/getting-started"},
                {"documentation", "/docs"},
                {"documentation/tasks", "/docs/fundamentals/tasks"},
                {"documentation/dependencies", "/docs/fundamentals/dependencies"},
                {"documentation/criteria", "/docs/fundamentals/criteria"},
                {"documentation/error-handling", "/docs/fundamentals/error-handling"},
                {"documentation/error-reporting", "/docs/fundamentals/error-handling"},
                {"documentation/finally-block", "/docs/fundamentals/finally-block"},
                {"documentation/setup-and-teardown", "/docs/fundamentals/setup-and-teardown"},
                {"documentation/running-targets", "/docs/fundamentals/running-targets"},
                {"documentation/script-aliases", "/docs/fundamentals/aliases"},
                {"contribute", "/docs/contributing/guidelines"},
                {"contribute/contribution-guidelines", "/docs/contributing/guidelines"}
            };

            var index = 1;
            foreach (var pair in lookup)
            {
                routes.MapRoute(
                    $"Legacy{index}",
                    pair.Key,
                    new { controller = "Redirect", action = "Index", path = pair.Value});

                index++;
            }
        }

Usage Example

Пример #1
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            // Legacy routes
            LegacyRouteConfig.RegisterRoutes(routes);

            // Documentation
            routes.MapRoute(
                "Documentation", "docs/{*path}",
                new { controller = "Docs", action = "index" }
                );

            // DSL Reference
            routes.MapRoute(
                "DSL", "dsl/{*path}",
                new { controller = "Dsl", action = "index" }
                );

            // API Reference
            routes.MapRoute(
                "API", "api/",
                new { controller = "Api", action = "index" }
                );

            // API Reference: Namespace
            routes.MapRoute(
                "Namespace", "api/{namespaceId}",
                new { controller = "Api", action = "namespace" }
                );

            // API Reference: Type
            routes.MapRoute(
                "Type", "api/{namespaceId}/{typeId}",
                new { controller = "Api", action = "type" }
                );

            // API Reference: Method
            routes.MapRoute(
                "Member", "api/{namespaceId}/{typeId}/{memberId}",
                new { controller = "Api", action = "member" }
                );

            // Blog: Index
            routes.MapRoute(
                "Blog", "blog/",
                new { controller = "Blog", action = "index" }
                );

            // Blog: Category
            routes.MapRoute(
                "BlogCategory", "blog/category/{category}",
                new { controller = "Blog", action = "index" }
                );

            // Blog: Archive
            routes.MapRoute(
                "BlogArchive", "blog/archive/{year}/{month}",
                new { controller = "Blog", action = "index" }
                );

            // Blog: Archive
            routes.MapRoute(
                "BlogArchiveYear", "blog/archive/{year}",
                new { controller = "Blog", action = "index" }
                );

            // Blog: Post
            routes.MapRoute(
                "BlogPost", "blog/{year}/{month}/{slug}",
                new { controller = "Blog", action = "Details" }
                );

            // Blog: Feed
            routes.MapRoute(
                "BlogFeed", "blog/feed/{format}",
                new { controller = "Blog", action = "Feed" }
                );

            // Addins
            routes.MapRoute(
                "Addins", "addins/",
                new { controller = "Addin", action = "index" }
                );

            // Addins: Category
            routes.MapRoute(
                "AddinsCategory", "addins/category/{category}",
                new { controller = "Addin", action = "index" }
                );

            RegisterDownloads(routes);

            // Default
            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
                );
        }
LegacyRouteConfig