Пример #1
0
        public void MappingRoot()
        {
            var routes = new RouteCollection();

            routes.MapRoot("Patients", "Index");
            Assert.AreEqual("Patients", routes.Root().Values["controller"]);
            Assert.AreEqual("Index", routes.Root().Values["action"]);
        }
Пример #2
0
        public virtual UrlInfo TokenizeUrl(string rawUrl, Uri uri, bool isLocal, string appVirtualDir)
        {
            if (rawUrl.TrimEnd('/').ToLower() == appVirtualDir.ToLower())
            {
                var root = routes.Root();
                return(new UrlInfo(uri.Host, uri.Host, appVirtualDir, uri.Scheme, uri.Port, rawUrl,
                                   "", root.GetRequiredString("controller"), root.GetRequiredString("action"), ""));
            }

            var routeData = routes.GetRouteData(Context);

            if (routeData == null)
            {
                throw new HttpException(404, "The resource cannot be found");
            }

            var values     = routeData.Values;
            var controller = routeData.GetRequiredString("controller");
            var action     = routeData.GetRequiredString("action");

            RewritePath(values, uri.Query);

            return(new UrlInfo(uri.Host, uri.Host, appVirtualDir,
                               uri.Scheme, uri.Port, rawUrl, "", controller, action, ""));
        }
Пример #3
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.Root();
            routes.MapRoute("ClientRoute",
                        "tasks/{year}/{month}/{day}",
                        new { controller = "Home", action = "Index" },
                        new { httpMethod = new HttpMethodConstraint("GET") });
            routes.MapRoute("GetTasksByDate",
                        "api/tasks/{year}/{month}/{day}",
                        new {controller = "Tasks", action = "Index"},
                        new {httpMethod = new HttpMethodConstraint("GET")});
            routes.Resource("tasks", "api");
        }
Пример #4
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.Root();
            routes.MapRoute("ClientRoute",
                            "tasks/{year}/{month}/{day}",
                            new { controller = "Home", action = "Index" },
                            new { httpMethod = new HttpMethodConstraint("GET") });
            routes.MapRoute("GetTasksByDate",
                            "api/tasks/{year}/{month}/{day}",
                            new { controller = "Tasks", action = "Index" },
                            new { httpMethod = new HttpMethodConstraint("GET") });
            routes.Resource("tasks", "api");
        }
Пример #5
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                "PostsPaged",
                "posts/{itemsPerPage}/{pageNumber}",
                new { controller = "Posts", action = "Index" },
                new { itemsPerPage = "\\d+", pageNumber = "\\d+", httpMethod = new HttpMethodConstraint("GET") }
                );
            
            routes.Root("Posts");

            routes.MapRoute(
                "PostPaginated", // Route name
                "Posts/{itemsPerPage}/{pageNumber}", // URL with parameters
                new {controller = "Posts", action = "Index"},
                new
                    {
                        itemsPerPage = @"\d+",
                        pageNumber = @"\d+",
                        httpMethod = new HttpMethodConstraint("GET")
                    });

            routes.MapRoute(
                "CommentPost", // Route name
                "posts/{slug}/comment", // URL with parameters
                new {controller = "Posts", action = "Comment"}, // Parameter defaults
                new {slug = @"[\w\-]+"}
                );

            routes.MapRoute(
                "RecentPosts", // Route name
                "RecentPosts", // URL with parameters
                new {controller = "Posts", action = "Last"},
                new {httpMethod = new HttpMethodConstraint("GET")}
                );

            routes.Resource("Posts");

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new {controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults
                );
        }
 public void MappingRoot()
 {
     var routes = new RouteCollection();
     routes.MapRoot("Patients", "Index");
     Assert.AreEqual("Patients", routes.Root().Values["controller"]);
     Assert.AreEqual("Index", routes.Root().Values["action"]);
 }