Thomas James
Thomas James

Reputation: 511

Mono asp.net MVC2 routes working in windows .net-4.0 but not in mono-2.8

I have an interesting problem that seems to be eluding me.

Mono's xsp4 only seems to be applying the first route for all requests.

This working on windows:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");



    routes.MapRoute(
        "Identities",
        "{identity}",
        new { controller = "Identity", action = "Index" }
        );

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

    routes.MapRoute(
        "Static Routes",
        "",
        new { controller = "Home", action = "Index" }
        );
}

So when requesting /thomasvjames & /Home/About in windows everything works normally but when requesting /Home/About in mono xsp4 it still maps to the "Identities" route and the identity parameter is set to "Home".

So have i uncovered (a hopefully existing) mono bug or can i rearrange my routes to make this work for both platforms?

I've also tried a catch-all type identity route with a constraint, but was unable to get this to work in mono as well.

[Edited: The Answer] So the answer to this question was, upgrade to the latest available build of mono. I wasnt using a recent enough build of 2.8 (oct) when i required the nov build.

Problem solved, the below works as expected.

Upvotes: 2

Views: 572

Answers (1)

Brian
Brian

Reputation: 7146

The MVC book I have indicates the correct approach is to put MORE specific entries before LESS specific entries, so according to that your ordering is wrong. The reason given for this is exactly what you described: It traverses the list in order and finds the first entry that matches.

With these changes your routing table should be: `

    routes.MapRoute(
    "Static Routes",
    "",
    new { controller = "Home", action = "Index" }
    );

    routes.MapRoute(
    "Identities",
    "{identity}",
    new { controller = "Identity", action = "Index" }
    );

   routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );

Upvotes: 1

Related Questions