/// <summary> /// 设置本地cookie /// </summary> /// <param name="minutes">过期时长,单位:分钟</param> public void SetCookie(string key, string value, int minutes = 0) { HttpContext.Response.Cookies.Append(key, value, ComHelper.GetCookieOpetion()); }
/// <summary> /// Action执行中触发委托 /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { ModelLoginUser mlUser = null; filterContext.HttpContext.Request.Cookies.TryGetValue(ComConst.UserLogin, out string value); if (value != null) { mlUser = JsonHelper.JsonToT <ModelLoginUser>(value); } if (null == mlUser || mlUser.School == null) { var XRWStrs = filterContext.HttpContext.Request.Headers["X-Requested-With"]; if (XRWStrs.Contains("XMLHttpRequest")) { filterContext.HttpContext.Response.WriteAsync("redirectUrl,/Login"); } else { filterContext.Result = new RedirectResult("~/Login"); } } else { filterContext.HttpContext.Response.Cookies.Append(ComConst.UserLogin, JsonHelper.ToJson(mlUser), ComHelper.GetCookieOpetion()); filterContext.HttpContext.Session.SetString(ComConst.UserLogin, JsonHelper.ToJson(mlUser)); } }