是否有可能有两条路线的区域。例如:
[RouteArea("{culture}/testarea")] <-- specific culture
[RouteArea("testarea")] <-- default culture
LocalizableAreaBaseController ....
谢谢你!
是否有可能有两条路线的区域。例如:
[RouteArea("{culture}/testarea")] <-- specific culture
[RouteArea("testarea")] <-- default culture
LocalizableAreaBaseController ....
谢谢你!
RouteArea 属性中还有另一个前缀,请使用它。那会奏效。
[RouteArea("testarea"),AreaPrefix="{culture}/testarea"]
<-- 特定文化
您可以通过路由约束来完成此操作。
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 }
);
}
}
或者
[RoutePrefix("{culture:regex(^[A-Za-z]{2}(\-[A-Za-z]{2})$)}/TestArea")]
[RoutePrefix("TestArea")]
public class TestController : ApiController {
}
(这个特殊的正则表达式约束将匹配“en”或“en-gb”之类的东西)