zoukankan      html  css  js  c++  java
  • 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();
            }
  • 相关阅读:
    Connection termination(by client)” 错误的处理方法
    Loadrunner教程读后感-VuGen
    通过HP Loadrunner VuGen来录制安卓的应用
    Test Android with QTP
    Junit单步调试
    魔法方法
    手写配置文件
    理解self与this
    幂等性
    Python assert作用
  • 原文地址:https://www.cnblogs.com/xiashenbin/p/4171134.html
Copyright © 2011-2022 走看看