Ejemplo n.º 1
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            if (!context.HttpContext.User.Identity.IsAuthenticated)
            {
                return;
            }
            MethodInfo method = context.GetHandlerMethod();

            if (method == null || method.CustomAttributes.Any(x => x.AttributeType == typeof(IgnorePageLockAttribute)))
            {
                return;
            }

            var tokenId = context.HttpContext.User.GetTokenIdOrNull();
            var isLock  = _cacheService.Get <bool>(string.Format(CacheKeyDefinition.PageLock, tokenId));

            if (isLock)
            {
                if (context.HttpContext.Request.IsJsonRequest())
                {
                    context.Result = new JsonResult(new
                    {
                        code    = 905,
                        message = "页面已锁定"
                    });
                }
                else
                {
                    var url = context.HttpContext.Request.Path.Value;
                    context.Result = new RedirectResult("/Account/Lock?ReturnUrl=" + WebUtility.UrlEncode(url));
                }
            }
        }