Exemplo n.º 1
0
        //<summary>
        //1.  kiem tra phan quyen khi hien len view - object ltsPermissionrole
        //2.  kiem tra phan quyen khi thuc hien action - object ltsPermission
        //</summary>
        //<author> linhtx </author>
        //<datemodified> 15-Jan-2014 </datemodified>
        //<param name="filterContext"></param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            var code = CodeLogin();

            if (code == "0")
            {
                filterContext.Result = new RedirectResult("/Account/Logon?url=" + Request["url"]);
            }
            else
            {
                UserItem = GetUser(code);
                if (UserItem != null && UserItem.UserName != null && UserItem.RoleId != Guid.Empty)
                {
                    if (Mid != ModuleId())
                    {
                        Mid = ModuleId();
                        GetTitle(ConvertUtil.ToInt32(ModuleId()));
                    }
                    UserName         = UserItem.UserName;
                    UserId           = UserItem.UserId;
                    SystemActionItem = new SystemActionItem();
                    var moduleArr = RawUrl();
                    var module    = moduleArr[1]; // ProductAttribute
                    if (moduleArr.Any(m => m.ToLower() == WebConfig.AdminUrl.ToLower()))
                    {
                        var keyCache = "ltsPermissionrole" + code; // ltsPermissionProductAttribute
                        if (HttpRuntime.Cache[keyCache] == null)
                        {
                            HttpRuntime.Cache[keyCache] = CheckAdmin(UserItem.listRole);
                        }
                        IsAdmin = (bool)HttpRuntime.Cache[keyCache];
                        SystemActionItem.IsAdmin = IsAdmin;
                        if (!SystemActionItem.IsAdmin)
                        {
                            var keyCacheModule = "ltsPermission" + code + "-" + module; // ltsPermissionProductAttribute
                            #region user module active
                            if (HttpRuntime.Cache[keyCacheModule] == null)
                            {
                                LtsModuleActive = UserRoleModule(module);
                                if (LtsModuleActive.Any())
                                {
                                    HttpRuntime.Cache[keyCacheModule] = LtsModuleActive;
                                }
                                else if (!string.IsNullOrEmpty(module) && module.ToLower() != "admindn")
                                {
                                    filterContext.Result = new RedirectResult("/AdminDN/NotRoles");
                                }
                                else
                                {
                                    SystemActionItem.IsAdmin = true;
                                }
                            }
                            else
                            {
                                LtsModuleActive = HttpRuntime.Cache[keyCacheModule] as List <ActionActiveItem>;
                            }
                            #endregion
                        }
                    }
                }
                else
                {
                    filterContext.Result = new RedirectResult("/Account/Logon?url=" + Request["url"]);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 1.  kiem tra phan quyen khi hien len view - object ltsModuleActive
        /// 2.  kiem tra phan quyen khi thuc hien action - object systemActionItem
        /// </summary>
        /// <author> linhtx </author>
        /// <datemodified> 15-Jan-2014 </datemodified>
        /// <param name="filterContext"></param>
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            if (Request.Url != null)
            {
                if (User.Identity.IsAuthenticated)
                {
                    var membershipUser = Membership.GetUser();
                    if (membershipUser != null)
                    {
                        SystemActionItem = new SystemActionItem();
                        var providerUserKey = membershipUser.ProviderUserKey;
                        if (providerUserKey != null)
                        {
                            var userId = (Guid)providerUserKey;
                            var path   = Request.Url.AbsolutePath.ToLower() + "/";
                            if (path.Contains(WebConfig.AdminUrl))
                            {
                                path = path.Replace(WebConfig.AdminUrl, "");
                                string[] moduleArr = path.Split('/');
                                if (Mid != moduleArr[0])
                                {
                                    Mid   = moduleArr[0];
                                    Title = moduleDa.GetNameByTag(Mid.ToLower());
                                }
                                var keyCache = "ltsPermissionrole" + userId; // ltsPermissionProductAttribute
                                if (HttpRuntime.Cache[keyCache] == null)
                                {
                                    HttpRuntime.Cache[keyCache] = CheckAdmin();
                                }
                                SystemActionItem.IsAdmin = (bool)HttpRuntime.Cache[keyCache];
                                if (!SystemActionItem.IsAdmin)
                                {
                                    var module         = moduleArr[0];                      // ProductAttribute
                                    var keyCacheModule = "ltsPermission" + userId + module; // ltsPermissionProductAttribute
                                    #region user module active

                                    if (HttpRuntime.Cache[keyCacheModule] == null)
                                    {
                                        LtsModuleActive = UserRoleModule(userId, module);
                                        if (LtsModuleActive.Any())
                                        {
                                            HttpRuntime.Cache[keyCacheModule] = LtsModuleActive;
                                        }
                                        else
                                        {
                                            if (!string.IsNullOrEmpty(module))
                                            {
                                                filterContext.Result = new RedirectResult("/AccountAdmin");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        LtsModuleActive = HttpRuntime.Cache[keyCacheModule] as List <ActionActiveItem>;
                                    }
                                    #endregion
                                }
                            }
                        }
                    }
                }
            }
        }