MVC Filter中加入验证并跳转
public class BuildingFilter : ActionFilterAttribute { /// <summary> /// 验证 Building Cookie add xia 验证是否登陆,是否选择案场 /// </summary> /// <param name="filterContext"></param> public override void OnActionExecuting(ActionExecutingContext filterContext) { var cookie = filterContext.HttpContext.Request.Cookies[FormsAuthentication.FormsCookieName]; if (cookie == null) { filterContext.Result = new RedirectResult("/Login/LoginOut"); return; } var buildingCookie = filterContext.HttpContext.Request.Cookies["Building"]; if (buildingCookie == null) { filterContext.Result = new RedirectResult("/BuildingList/Index"); return; } else { long buildingSysNo; long relationSysNo; //关系SysNo long.TryParse(buildingCookie.Values["RelationSysNo"], out relationSysNo); //案场SysNo long.TryParse(buildingCookie.Values["BuildingSysNo"], out buildingSysNo); if (buildingSysNo == 0 || relationSysNo == 0) { filterContext.Result = new RedirectResult("/BuildingList/Index"); return; } } base.OnActionExecuting(filterContext); } }
我是验证是否登陆和是否选择案场【一并验证】
使用方法如下:
/// <summary> /// 签约列表 -GET /// </summary> /// <returns></returns> [BuildingFilter] public ActionResult ContractOrderList() { return View(); }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。