public override void OnActionExecuted(ActionExecutedContext filterContext) { if (!MyRoleManager.hasRole(MyRoleManager.RoleType.SYSTEMADMIN) && !MyRoleManager.hasRole(MyRoleManager.RoleType.MARKETING) && !MyRoleManager.hasRole(MyRoleManager.RoleType.DCEADMIN)) { filterContext.RequestContext.HttpContext.Response.Redirect("/Dashboard/Dashboard"); } }
//public static bool canAccessPage(string path) //{ // PCMSDBContext db = new PCMSDBContext(); // string username = getCurrentName(); // if (accessablePath.Contains(path)) return true; // UserRole roles = db.UserRoles.Where(r => r.username == username).FirstOrDefault(); // if (roles == null) return false; // bool ret = db.AccessAuthorities.Where(p => p.AccessPaths.path.Equals(path) && p.roleID == (int)roles.roletype).Count() > 0; // if (ret) accessablePath.Add(path); // return ret; //} public static bool canAccessPage(string path) { PCMSDBContext pcmsdbContext = new PCMSDBContext(); string username = MyRoleManager.getCurrentName(); UserRole roles = ((IQueryable <UserRole>)pcmsdbContext.UserRoles).Where <UserRole>((Expression <Func <UserRole, bool> >)(r => r.username == username)).FirstOrDefault <UserRole>(); if (roles == null) { return(false); } if (MyRoleManager.accessablePath.Contains(path) && roles.roletype != (MyRoleManager.RoleType)MyRoleManager.roleId) { MyRoleManager.accessablePath.Clear(); } else if (MyRoleManager.accessablePath.Contains(path)) { return(true); } bool flag = ((IQueryable <AccessAuthorities>)pcmsdbContext.AccessAuthorities).Where <AccessAuthorities>((Expression <Func <AccessAuthorities, bool> >)(p => p.AccessPaths.path.Equals(path) && p.roleID == (int)roles.roletype)).Count <AccessAuthorities>() > 0; if (flag) { MyRoleManager.accessablePath.Add(path); MyRoleManager.roleId = (int)roles.roletype; } return(flag); }