我需要在 OnActionExeuting 中获取当前区域名称。我得到它如下:
_areaName = ctx.RouteData.DataTokens["area"].ToString();
这适用于除默认路由(我的登录页面 - 登录)之外的所有路由。默认路由在 global.asax 中定义如下
public static void RegisterRoutes(RouteCollection routes)
{
routes.Ignore("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{area}/{controller}/{action}/{id}",
new {area = "Home",
controller = "UserLogon",
action = "Login",
id = UrlParameter.Optional
}
);
}
区域注册如下:
public override string AreaName
{
get
{
return "Home";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Home_default",
"Home/{controller}/{action}/{id}",
new {controller = "UserLogon", action = "Login", id = UrlParameter.Optional }
);
}
我错过了什么?