本文整理汇总了C#中RouteCollection.Root方法的典型用法代码示例。如果您正苦于以下问题:C# RouteCollection.Root方法的具体用法?C# RouteCollection.Root怎么用?C# RouteCollection.Root使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RouteCollection
的用法示例。
在下文中一共展示了RouteCollection.Root方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RegisterRoutes
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");
}
示例2: RegisterRoutes
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
);
}
示例3: MappingRoot
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"]);
}