ASP.NET MVC Filter- 登录验证 【异步刷新列表视图】
1 public class TAjaxListLoginValidateAttribute : FilterAttribute, IAuthorizationFilter 2 { 3 public void OnAuthorization(AuthorizationContext filterContext) 4 { 5 try 6 { 7 if (!TUser.IsLogin()) 8 { 9 var viewResult = new ViewResult(); 10 viewResult.ViewName = "~/Views/Error/NeedLogin.cshtml"; 11 if (filterContext.HttpContext.Request.UrlReferrer != null) 12 viewResult.ViewBag.ReturnUrl = HttpUtility.UrlEncode(filterContext.HttpContext.Request.UrlReferrer.AbsolutePath); 13 filterContext.Result = viewResult; 14 } 15 16 } 17 catch (Exception ex) 18 { 19 20 Log.Fatal(ex, "TAjaxLoginValidateAttribute::OnAuthorization(AuthorizationContext filterContext)", TLogMessage.FilterError); 21 } 22 } 23 }