1)过滤器中的:
- public class CMSAttribute : FilterAttribute, IAuthorizationFilter
- {
- public void OnAuthorization(AuthorizationContext filterContext)
- {
- var controllerName = (filterContext.RouteData.Values["controller"]).ToString().ToLower();
- var actionName = (filterContext.RouteData.Values["action"]).ToString().ToLower();
- var areaName = (filterContext.RouteData.DataTokens["area"] == null ? "" : filterContext.RouteData.DataTokens["area"]).ToString().ToLower();
2)视图中的:
- @{
- //获取当前路由的区域名称
- var areaName = (ViewContext.RouteData.DataTokens["area"] == null ? "" : ViewContext.RouteData.DataTokens["area"]).ToString().ToLower();
- var actionName=ViewContext.RouteData.Values["action"].ToString().ToLower();
- var controllerName = ViewContext.RouteData.Values["controller"].ToString().ToLower();
- }
3)action中:
- string areaName=RouteData.DataTokens["area"].ToString().ToLower();
- string controllerName = RouteData.Values["controller"].ToString().ToLower();
- string actionName = RouteData.Values["action"].ToString().ToLower();