views:

264

answers:

3

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!

A: 

You're misunderstanding the MapRoute extension method.

The third parameter is a set of default values for the route parameters.

In your case, you're telling it that the default value for the id parameter is \d{1,}.

SLaks
+4  A: 
LukLed
A: 

Edit: solved.

[HandleError]

will pass (automatically) the Exception Object to the Error.aspx View, which display the inner message.

<customErrors mode="On" defaultRedirect="/Error/NotFound" />

will call the ErrorController method "NotFound" which display a (static) aspx View.

Gremo
You can define additional route for Edit with new {productId = @"\d+" }.
LukLed