首页 > 代码库 > MVC Filter中加入验证并跳转
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(); }
MVC Filter中加入验证并跳转
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。