views:

147

answers:

1

I tried to use the solution explained at http://weblogs.asp.net/paulomorgado/archive/2010/01/31/web-site-globalization-with-asp-net-routing.aspx to localize my application using the language parameter in my routes.

Here's the code I have in my Global.asax:

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

        routes.Add("en", new Route("en/{*path}", new GlobalizationRouteHandler(CultureInfo.GetCultureInfo("en-US"))));
        routes.Add("fa", new Route("fa/{*path}", new GlobalizationRouteHandler(CultureInfo.GetCultureInfo("fa-IR"))));

        routes.MapRoute(
            "AdminHome",
            "{language}/admin",
            new { controller = "Admin", action = "Index" }
        );

    }

But when I point my browser to /en/admin or /fa/admin I receive a 404 error message.

I tried this one too:

routes.MapRoute(
        "AdminHome",
        "admin",
        new { controller = "Admin", action = "Index" }
    );

But still a 404 error for /en/admin - (in this case "/admin" works.)

Any idea?

A: 

I have a very similar route pattern in my own MVC site.

            routes.MapRoute(
            "BlogSpecific",                                              // Route name
            "{blogSubFolder}/{controller}/{action}",                           // URL with parameters
            new { blogSubFolder = "", controller = "", action = "Index" }  // Parameter defaults
        );

The two main differences that I can see are that I specify the {action} in my route, and I also call out the first route param as a parameter in my object ("blogSubFolder = "",").

Now I just did some testing, and I found the same behavior that you are seeing, I take out the {action} out of my route and I get a 404. But if I specify the action everything works out.

Ok, so I created a new project, with the default route, and I don't have to specify the action, it defaults to Index just like I'd expect it to. I then add a new route where I specify the controller {language}/Foo/{action}, and I continue to get errors if I don't include the index in my url. Long story short, As near as I can tell if your route has a variable that precedes the controller you have to specify the action in your url.

Arthur C