protected override voidOnAuthorization(AuthorizationContext filterContext)
{if(filterContext.HttpContext.User.Identity.IsAuthenticated)
{string CurrController = filterContext.RouteData.Values["controller"].ToString();string CurrAction = filterContext.RouteData.Values["action"].ToString();
FormsIdentity id=(FormsIdentity)filterContext.HttpContext.User.Identity;
FormsAuthenticationTicket ticket=id.Ticket;if (!string.IsNullOrEmpty(ticket.UserData))
{//string userCacheKey = string.Format("ST_User_{1}_{0}", ticket.UserData.Split('|').First(), Session.SessionID);
string menuCacheKey = string.Format("ST_Menu_{1}_{0}", ticket.UserData.Split('|').First(), Session.SessionID);
_CurrentUser= Factory.UserRepository.GetUserByUserId(int.Parse(ticket.UserData));
ViewData["User"] =_CurrentUser.Name;//AJAX not need Menu
if (Array.IndexOf(_arySkipController, CurrController.ToUpper()) == -1)
{if (filterContext.HttpContext.Cache[menuCacheKey] == null
|| Session["refresh_menu"] != null)
{
filterContext.HttpContext.Cache[menuCacheKey]= CaculateMenu(null);
Session.Remove("refresh_menu");
}
ViewData["Menu"] = filterContext.HttpContext.Cache[menuCacheKey] as IEnumerable;
List Functions =Factory.UserRepository.GetFunctionsByUserId(_CurrentUser.UserId).ToList();if (Session["Error"] != null)
{
Session["Error"] = null;
filterContext.Result= newHttpUnauthorizedResult();return;
}if (_CurrentUser.FirstLogin || _CurrentUser.Reset_Password_Due_Date <=DateTime.Now)
{if (CurrController.ToUpper() == "ACCOUNT" &&(CurrAction.ToUpper()== "CHANGEPASSWORD" || CurrAction.ToUpper() == "LOGOUT"))
{return;
}else{
SetFlashMsg("you must change your password.");
filterContext.Result= RedirectToAction("ChangePassword", "Account");
}
}if(
(CurrController.ToUpper()!= "HOME" && CurrAction.ToUpper() != "INDEX")&& (CurrController.ToUpper() != "ACCOUNT" && (CurrAction.ToUpper() != "LOGON" || CurrAction.ToUpper() != "LOGOUT"))
)
{
List CheckEntity = Functions.Where(f => f.Controller ==CurrController&& f.Action ==CurrAction).ToList();if (CheckEntity == null || CheckEntity.Count == 0)
{
Session["Error"] = "Y";
filterContext.Result= newHttpUnauthorizedResult();return;
}
}
}
}
}
ViewData["SystemVersion"] = "Version:" +Assembly.GetExecutingAssembly().GetName().Version.ToString();base.OnAuthorization(filterContext);
}