Bảng định tuyến (route table) được tạo như thế nào trong ASP.NET MVC?
Bảng định tuyến (route table) được tạo như thế nào trong ASP.NET MVC?
Bảng định tuyến (RouteTable.Routes) được tạo lúc khởi động ứng dụng:
// Global.asax.cs
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes); // đăng ký route
}
// App_Start/RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes(); // attribute routes (trước)
routes.MapRoute("Blog", "blog/{year}/{slug}", new { controller = "Blog", action = "Post" }, new { year = @"\d{4}" }); // route cụ thể
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.