Beispiel #1
0
        public override void OnActionExecuting(ActionExecutingContext loigncontext)
        {
            HttpContext.Session.TryGetValue("UserId", out byte[] result);
            HttpContext.Session.TryGetValue("UserSession", out byte[] session);
            // 没有 session 或过期时跳转到的页面
            if (result == null || session == null)
            {
                loigncontext.Result = new RedirectResult("/Login/Index");
                //RedirectToAction("Index", "Login");
                return;
            }
            else
            {
                var       id         = System.Text.Encoding.UTF8.GetString(result);
                var       strSession = System.Text.Encoding.UTF8.GetString(session).ToUpper();
                AdminUser user       = _AdminUserContext.LoginSession(id);

                if (user == null || !(user.SessionKey == strSession))
                {
                    loigncontext.Result = new RedirectResult("/Login/Index");
                    //RedirectToAction("Index", "Login");
                    return;
                }
            }
            base.OnActionExecuting(loigncontext);
        }