我需要在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 }
);
}
我错过了什么?