I know that the first route will catch most of the paths. However, this will catch also /Product/Edit/blablabla (i’m using ASP.NET Routing Debugger):
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = @"\d{1,}" }
);
routes.MapRoute(
"Catch All",
"{*path}",
new { controller = "Error", action = "NotFound" }
);
}
But this is wrong! Why? If not an integer of min 1 of length, the first route should not match. I need also to handle not found coutroller and action… any ideas?
Many thanks!
You should place expression in fourth parameter. Read this:
http://www.asp.net/LEARN/MVC/tutorial-24-cs.aspx
Listing 3.
The regular expression \d+ matches
one or more integers. This constraint causes the Product route to match
the following URLs:
But not the following URLs:
These browser requests will be
handled by another route or, if there are no matching routes, a The
resource could not be found error will be returned.