2

I have a web site that had no areas registered. Then I registered an area called "MyNewArea".

Now my default website links like blogs etc no longer work.

So I now have an areas folder with a single area in it and the default folders when I created the project in the first place.

In my area AreaRegistration class I have;

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "MyArea_default",
        "{controller}/{action}/{id}",
        new { action = "Index", id = UrlParameter.Optional }
    );
}

but this looks like it conflicts with the default one of

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

What do I need to do to get the area to work with the default site and controllers?

gotnull
  • 26,454
  • 22
  • 137
  • 203
griegs
  • 22,624
  • 33
  • 128
  • 205

2 Answers2

2

You're right, that mapped route would conflict (in the sense of "conflict" as in it will be matched first). You would need to alter your mapped Area route to be something like:

        context.MapRoute(
            "MyArea_default",
            "MyArea/{controller}/{action}/{id}",
            new { controller = "MyAreaController", action = "Index", id = UrlParameter.Optional }
        );

The reason why your URLs broke after you added this Area (and in turn the Area route), it used your Area route for handling that didn't exist in your MyArea Area.

  • 1
    I still need to specify the controller to use else the same issue occures. – griegs Mar 05 '12 at 02:15
  • @griegs Well technically you don't. That is simply for parameter defaults. So yes, if you don't explicity specify a controller you will have an issue. But I have edited my answer to include the default of the `controller`. –  Mar 05 '12 at 02:20
1

Change the new area route table to be:

context.MapRoute(
    "MyArea_default",
    "MyNewArea/{action}/{id}",
    new { controller = "MyNewArea", action = "Index", id = UrlParameter.Optional }
);
gotnull
  • 26,454
  • 22
  • 137
  • 203