string controller = ViewContext.RouteData.Route.GetRouteData(this.Context).Values["controller"].ToString(); string controller = ViewContext.RouteData.Values["controller"].ToString();
보기
2. Controller의 action
string controller = RouteData.Route.GetRouteData(this.HttpContext).Values["controller"].ToString(); string controller = RouteData.Values["controller"].ToString();
3. Filter
ActionFilterAttribute는 이때 일반적으로 상속 클래스를 구현한 후 해당 메서드를 재정의합니다. >
4. . 공개 메서드에서/// <summary> /// 验证权限,用于检查用户是否已经登录(action执行前会先执行这里) /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); string controller = filterContext.RouteData.Values["controller"].ToString(); controller = controller + "Controller"; }
/// <summary> /// 获取当前页面的Controller全名称 /// </summary> /// <returns></returns> public string GetCurrentController() { string controller = HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString(); if (!string.IsNullOrWhiteSpace(controller)) { controller = controller + "Controller"; } else { controller = ""; } return controller; }