public void OnAuthorization(AuthorizationContext filterContext) { if (filterContext.HttpContext.Session != null) { var Suser = filterContext.HttpContext.Session["user"]; var user = (Suser != null ? Suser.ToString() : " "); if (!string.IsNullOrWhiteSpace(user)) { return; } var cookie = filterContext.HttpContext.Request.Cookies["user"]; var temp = (cookie != null ? cookie.ToString() : " "); if (string.IsNullOrWhiteSpace(temp)) { throw new UnauthorizedException(); } var content = temp.DecryptQueryString(); CourseManagerEntities db = new CourseManagerEntities(); if (!db.Users.Any(u => u.Account == content)) { throw new UnauthorizedException(); } } }
public void OnAuthorization(AuthorizationContext filterContext) { if (filterContext.HttpContext.Session != null) { var user = filterContext.HttpContext.Session["user"]?.ToString(); if (!string.IsNullOrWhiteSpace(user)) { return; } var cookie = filterContext.HttpContext.Request.Cookies?["user"]; if (string.IsNullOrEmpty(cookie?.Value)) { throw new UnauthorizedException(); } var content = cookie?.Value.DecryptQueryString(); CourseManagerEntities db = new CourseManagerEntities(); if (db.Users.Any(u => u.Account == content)) { throw new UnauthorizedException(); } } }