public override void OnAuthorization(AuthorizationContext filterContext) { this.actionUrl = PermissionUtil.CurrentPermissionUrl(filterContext); this.rawUrl = PermissionUtil.CurrentUrl(filterContext); base.OnAuthorization(filterContext); }
public void OnAuthorization(AuthorizationFilterContext context) { context.ThrowIfNull(); _currentUrl = PermissionUtil.CurrentUrl(context.HttpContext); //不需要验证登录的直接跳过 if (context.Filters.Count(a => a is AllowAnonymousFilter) > 0) { return; } var user = GetCurrentUser(context); if (user == null) { if (_noCheckPage.Contains(_currentUrl)) { return; } _unauthorizedMessage = "登录失效"; if (context.HttpContext.Request.IsAjax()) { NoUserResult(context); } else { LogoutResult(context); } return; } //超级管理员跳过 if (user.IsSuper) { return; } //账号状态判断 var administrator = _administratorService.GetById(user.UserId); if (administrator != null && administrator.Status != EAdministratorStatus.Normal) { if (_noCheckPage.Contains(_currentUrl)) { return; } _unauthorizedMessage = "亲~您的账号已被停用,如有需要请您联系系统管理员"; if (context.HttpContext.Request.IsAjax()) { AjaxResult(context); } else { AuthResult(context, 403, GoErrorPage(true)); } return; } if (_noCheckPage.Contains(_currentUrl)) { return; } var userUrl = _administratorService.GetUserCanPassUrl(user.UserId); // 判断菜单访问权限与菜单访问权限 if (IsMenuPass(userUrl) && IsActionPass(userUrl)) { return; } if (context.HttpContext.Request.IsAjax()) { AuthResult(context, 200, GetJsonResult()); } else { AuthResult(context, 403, GoErrorPage()); } }