asp.net mvc 3 获取路由领域名
----------------------------------------------------------------
一、注册路由
public class SysAreaRegistration : AreaRegistration
{
/// <summary>
/// MVC 路由领域名称
/// </summary>
public override string AreaName
{
get
{
return "Sys";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
string[] controllerNamespaces = new string[] { "Grass.Sys.Controllers" };
context.MapRoute(
"Sys_default",
"Sys/{controller}/{action}",
new { controller = "Login", action = "Index" },
null,
controllerNamespaces
);
}
}
----------------------------------------------------------------
二、获取路由领域名
/// <summary>
/// MVC 路由领域名称
/// </summary>
public static string AreaName
{
get
{
HttpContextBase httpContext = new HttpContextWrapper(HttpContext.Current);
RouteData rd = RouteTable.Routes.GetRouteData(httpContext);
return rd.DataTokens["area"].GetString();
}
}