u013895251
無耐
2019-12-09 15:53

Asp.Net Core 配合vue Session丢失跳转登录页面

80
  • c#
  • asp.net
  • visual studio

在BaseController中一个拦截器发现session丢失后想回馈给前端session丢失跳转登录页

跨域 前后端分离

public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var isDefined = false;
            //创建一个行动限制ActionDescriptor
            var controllerActionDescriptor = filterContext.ActionDescriptor as ControllerActionDescriptor;
            //执行方法是否存在NoPermissionRequired
            if (controllerActionDescriptor != null)
            {
                isDefined = controllerActionDescriptor.MethodInfo.GetCustomAttributes(inherit: true).Any(a => a.GetType().Equals(typeof(NoPermissionRequiredAttribute)));
            }
            //判断是否拦截
            if (isDefined) return;
            byte[] result;
            //获取session
            filterContext.HttpContext.Session.TryGetValue(KeyUtil.user_info, out result);
            //判断session是否存在
            if (result == null)
            {

                //在此处如何让vue能跳转到登录页
                return;
            }
            base.OnActionExecuting(filterContext);
        }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答