Пример #1
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            object[] customAttributes = filterContext.ActionDescriptor.GetCustomAttributes(typeof(MyAttributeAttribute), false);
            bool     flag1            = true;
            bool     flag2            = true;
            bool     flag3            = true;

            if (customAttributes.Length == 1)
            {
                MyAttributeAttribute attributeAttribute = (MyAttributeAttribute)customAttributes[0];
                flag1 = attributeAttribute.CheckLogin;
                flag2 = attributeAttribute.CheckApp;
                flag3 = attributeAttribute.CheckUrl;
            }
            if (flag3 && !WebMvc.Common.Tools.CheckReferrer(false))
            {
                filterContext.Result = (ActionResult)this.Content("地址验证错误");
            }
            else
            {
                string msg1;
                if (flag1 && !this.CheckLogin(out msg1))
                {
                    if (filterContext.HttpContext.Request.IsAjaxRequest())
                    {
                        filterContext.Result = (ActionResult)this.Content("{\"loginstatus\":-1, \"url\":\"\"}");
                    }
                    else
                    {
                        string str = HttpContext.Current.Request.Url.PathAndQuery.UrlEncode();
                        filterContext.Result = (ActionResult)this.Content("<script>" + (msg1.IsNullOrEmpty() ? "" : string.Format("alert('{0}');", (object)msg1)) + (string.Compare(filterContext.Controller.ToString(), "WebMvc.Controllers.HomeController", true) == 0 ? "top.location='" + this.Url.Content("~/Login") + "'" : "top.lastURL='" + str + "';top.currentWindow=window;top.login();") + "</script>", "text/html");
                    }
                }
                else
                {
                    string msg2;
                    if (!flag2 || WebMvc.Common.Tools.CheckApp(out msg2, ""))
                    {
                        return;
                    }
                    filterContext.Result = (ActionResult)this.Content("权限验证错误");
                }
            }
        }
Пример #2
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            object[] customAttributes = filterContext.ActionDescriptor.GetCustomAttributes(typeof(MyAttributeAttribute), false);
            bool     flag             = true;
            bool     flag2            = true;
            bool     flag3            = true;

            if (customAttributes.Length == 1)
            {
                MyAttributeAttribute obj = (MyAttributeAttribute)customAttributes[0];
                flag  = obj.CheckLogin;
                flag2 = obj.CheckApp;
                flag3 = obj.CheckUrl;
            }
            string msg;
            string msg2;

            if (flag3 && !WebMvc.Common.Tools.CheckReferrer(false))
            {
                filterContext.Result = Content("地址验证错误");
            }
            else if (flag && !CheckLogin(out msg))
            {
                if (filterContext.HttpContext.Request.IsAjaxRequest())
                {
                    filterContext.Result = Content("{\"loginstatus\":-1, \"url\":\"\"}");
                }
                else
                {
                    string str = MyExtensions.UrlEncode(System.Web.HttpContext.Current.Request.Url.PathAndQuery);
                    filterContext.Result = Content("<script>" + (MyExtensions.IsNullOrEmpty(msg) ? "" : string.Format("alert('{0}');", msg)) + ((string.Compare(filterContext.Controller.ToString(), "WebMvc.Controllers.HomeController", true) == 0) ? ("top.location='" + base.Url.Content("~/Login") + "'") : ("top.lastURL='" + str + "';top.currentWindow=window;top.login();")) + "</script>", "text/html");
                }
            }
            else if (flag2 && !WebMvc.Common.Tools.CheckApp(out msg2))
            {
                filterContext.Result = Content("权限验证错误");
            }
        }