using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Routing; namespace FilmsRUsOnline { public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); // Original URL schema: /* routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Films", action = "List", id = UrlParameter.Optional } ); */ // Improved URL schema below... // Match the empty URL (i.e. ~/). routes.MapRoute( name: null, url: "", defaults: new { controller = "Films", action = "List", genre = (string)null, pageNumber = 1 } ); // Match ~/PageNumber2, ~/PageNumber123, but not ~/PageNumberXYZ routes.MapRoute( name: null, url: "PageNumber{pageNumber}", defaults: new { controller = "Films", action = "List", genre = (string)null }, constraints: new { pageNumber = @"\d+" } ); // Match ~/Childrens or anything without another / routes.MapRoute( name: null, url: "{genre}", defaults: new { controller = "Films", action = "List", pageNumber = 1 } ); // Match ~/Childrens/PageNumber2 routes.MapRoute( name: null, url: "{genre}/PageNumber{pageNumber}", defaults: new { controller = "Films", action = "List" }, constraints: new { pageNumber = @"\d+" } ); // Most generic route. routes.MapRoute( name: null, url: "{controller}/{action}/" ); } } }