1

is it possible to have area with two routes. for example:

[RouteArea("{culture}/testarea")] <-- specific culture
[RouteArea("testarea")]  <-- default culture
LocalizableAreaBaseController ....

Thank You!

shkipper
  • 1,403
  • 3
  • 21
  • 35

2 Answers2

1

You could accomplish this with a route constraint.

public class TestAreaAreaRegistration : AreaRegistration
{
    public override string AreaName
    {
        get
        {
            return "TestArea";
        }
    }

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRoute(
            "TestArea_culture",
            "{culture}/TestArea/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional },
            new { culture = @"^[A-Za-z]{2}(\-[A-Za-z]{2})$"}
        );

        context.MapRoute(
            "TestArea_default",
            "TestArea/{controller}/{action}/{id}",
            new { action = "Index", id = UrlParameter.Optional }
        );
    }
}

Or

[RoutePrefix("{culture:regex(^[A-Za-z]{2}(\-[A-Za-z]{2})$)}/TestArea")]
[RoutePrefix("TestArea")]
public class TestController : ApiController {
}

(This particular regex constraint would match something like "en" or "en-gb")

Jeremy Bell
  • 698
  • 5
  • 9
1

There is another prefix for that in RouteArea attribute please use that. That will works.

[RouteArea("testarea"),AreaPrefix="{culture}/testarea"] <-- specific culture

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
SimonOzturk
  • 791
  • 1
  • 5
  • 3