// check session when redirect protected override void OnActionExecuting(ActionExecutingContext filterContext) { if (!Request.IsAjaxRequest()) { var routeData = filterContext.RouteData; var controller = routeData.Values["controller"].ToString(); var action = routeData.Values["action"].ToString(); CommonService comService = new CommonService(); var check = ((controller != "UserAccount" && action != "Login") && (controller != "Home" && action != "Index") && (controller != "Home" && action != "Intro") && (controller != "PDFManage" && action != "ViewPdf") && (controller != "Home" && action != "SupportCenter") && (controller != "Common" && action != "AuthentTimeout") && (controller != "ManageNews" && action != "TopNews") && (controller != "ManageNews" && action != "ViewNews")); var sessionLogin = Session["CmnEntityModel"] as CmnEntityModel; if ((sessionLogin == null || sessionLogin.ID == 0) && check) { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary(new { controller = "Login", action = "Login" })); } int pos = Sitemap.FindIndex(item => item.ControllerName == controller && item.ActionName == action); if (0 <= pos) { Sitemap.RemoveRange(pos, 0); } else { var item = new SitemapItem { ControllerName = controller, ActionName = action, RestoreData = null }; Sitemap.Insert(0, item); } base.OnActionExecuting(filterContext); } }
/// <summary> /// This method is called before the acion method /// </summary> /// <param name="filterContext"></param> protected override void OnActionExecuting(ActionExecutingContext filterContext) { var routeData = filterContext.RouteData; var controller = routeData.Values["controller"].ToString(); var loginUser = GetLoginUser(); // Check login by license of user's company if (loginUser != null && controller != "PMS01001") { if (_service.CheckLicense(loginUser.CompanyCode) == 0) { if (Request.IsAjaxRequest()) { this.Response.StatusCode = 420; return; } else { filterContext.Result = new RedirectResult(Url.Action("", "ErrorOutOfDate")); return; } } } if (!Request.IsAjaxRequest()) { var action = routeData.Values["action"].ToString(); // Check user password is expired if (loginUser != null && action != "PersonalSetting" && action != "Logout" && action != "AuthentTimeout" && controller != "ErrorAuthent" && controller != "Error") { if (loginUser.Is_expired_password) { Session[Constant.PASSWORD_OUT_OF_DATE] = 1; filterContext.Result = new RedirectResult(Url.Action("PersonalSetting", "PMS01002")); return; } } int pos = Sitemap.FindIndex(item => item.ControllerName == controller); string[] controllerArr = { "PMS06001", "PMS09001", "PMS09002", "PMS09003", "PMS09004", "PMS09005" }; // Clear Jquery datatable state data if (controllerArr.Contains(controller) && action == "ClearSaveCondition" && 0 <= pos) { Sitemap[pos].RestoreData = null; } if (0 <= pos) { Sitemap.RemoveRange(pos, 0); } else { var item = new SitemapItem { ControllerName = controller, RestoreData = null }; Sitemap.Insert(0, item); } } base.OnActionExecuting(filterContext); }