public override void OnAuthorization(AuthorizationContext filterContext) { //判断是否跳过授权过滤器 if (filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true) || filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true)) { return; } //判断登录情况 if (filterContext.HttpContext.Session["user"] == null) { JsonResult jsonResult = new JsonResult(); ErrorResult error = new ErrorResult("user have not login"); error.setCode(1002); jsonResult.Data = error; jsonResult.JsonRequestBehavior = JsonRequestBehavior.AllowGet; filterContext.Result = jsonResult; } }