示例#1
0
        /// <summary>
        /// 获取用户登录信息
        /// </summary>
        /// <returns></returns>
        private LoginUserModel UserLogin(ActionExecutingContext filterContext)
        {
            var request = filterContext.HttpContext.Request;
            //获取登录信息
            LoginUserModel loginUserModel = LoginHelper.GetCurrentUserInfo();
            var            userid         = "" + Session[LoginHelper.SessionKey];
            int            id             = 0;

            if (!string.IsNullOrEmpty(userid))
            {
                int.TryParse(userid.ToString(), out id);
            }
            if (loginUserModel == null)
            {
                var loginKey = LoginHelper.GetCurrentCacheKey();
                if (id > 0)
                {
                    //从本地缓存中获取登录对象
                    loginUserModel = (LoginUserModel)HttpRuntime.Cache.Get(loginKey);
                }
                if (loginUserModel == null)
                {
                    if (id == 0 || ShieldUsers.Contains(userid))
                    {
                        filterContext.Result = Redirect(GetLoginUrl(filterContext.HttpContext.Request));
                    }
                    else
                    {
                        loginUserModel = adminUserBLL.GetLoginUserByUserID(id);
                        RedisCacheHelper.Add <LoginUserModel>(loginKey, loginUserModel, DateTime.Now.AddMinutes(Session.Timeout));
                    }
                }
            }
            else
            {
                /* 测试阶段暂时注销,待菜单稳定后打开
                 *
                 * if (filterContext.HttpContext.Request.Url.AbsolutePath.Equals("/"))
                 *  return loginUserModel;
                 * int urlHashCode = filterContext.HttpContext.Request.Url.AbsolutePath.GetHashCode();
                 * bool usable = false;
                 * //安全验证,判断请求的URL是否属于用户权限菜单
                 * foreach (var item in loginUserModel.MenuList)
                 * {
                 *  if (item.children != null)
                 *  {
                 *      foreach (var childMenu in item.children)
                 *      {
                 *          if (urlHashCode == childMenu.ModuleURL.GetHashCode())
                 *          {
                 *              usable = true;
                 *              break;
                 *          }
                 *      }
                 *
                 *      if (usable)
                 *          break;
                 *  }
                 * }
                 *
                 * if (!usable)
                 * {
                 *  filterContext.RequestContext.HttpContext.Response.Redirect("http://Admin.SFO2O.com/", true);
                 * }
                 */
            }

            return(loginUserModel);
        }