Example #1
0
        //
        // GET: /Home/

        public ActionResult Index(string url)
        {
            try
            {
                BaseAuthorizeModel auth = BaseAuthorizeHelper.GetAuthorizeModel(this.HttpContext);
                if (string.IsNullOrWhiteSpace(auth.TempDataMsg) == false)
                {
                    TempData["Msg"] = auth.TempDataMsg;
                }
                if (auth.IsAuthorize == false)
                {
                    string userAgent = Request.UserAgent;
                    return(RedirectToAction("Login", "Home", new { url = Request.Url.ToString() }));
                }
                B_User        user  = auth.CurrentSYSUser;
                List <B_Menu> menus = B_Menu.GetShowMenus();

                if (user.UserName != WeConfig.robot)
                {
                    menus.RemoveAll(m => m.IsRobot);
                }

                List <B_Role>       roles     = B_Role.GetUserRoles(user.UserName);
                List <B_MenuRights> rolerignt = B_MenuRights.GetRoleUser(roles[0].ID);
                ViewData["role"]     = (roles != null && roles.Count > 0) ? roles[0] : null;
                ViewData["menus"]    = menus;
                ViewData["url"]      = url;
                ViewData["UserRole"] = rolerignt;

                return(View(user));
            }
            catch (Exception ex)
            {
                DAL.Log.Instance.Write(ex.ToString());
                return(View(ErrorPage.ViewName, new ErrorPage {
                    Message = ex.ToString()
                }));
            }
        }
Example #2
0
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            ReflectedActionDescriptor descriptor = filterContext.ActionDescriptor as ReflectedActionDescriptor;

            if (descriptor != null)
            {
                Type actionType = descriptor.MethodInfo.ReturnType;
                if (actionType.Equals(typeof(ActionResult)))
                {
                    if (actionType.IsSubclassOf(typeof(JsonResult)))
                    {
                        actionResult = ReturnResult.Json;
                    }
                    else if (actionType.IsSubclassOf(typeof(ContentResult)))
                    {
                        actionResult = ReturnResult.Content;
                    }
                }
                else
                {
                    if (actionType.Equals(typeof(JsonResult)))
                    {
                        actionResult = ReturnResult.Json;
                    }
                    else if (actionType.Equals(typeof(ContentResult)))
                    {
                        actionResult = ReturnResult.Content;
                    }
                }
            }

            _ActionName     = filterContext.ActionDescriptor.ActionName;
            _ControllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;

            string _ControllerType = filterContext.ActionDescriptor.ControllerDescriptor.ControllerType.ToString();

            if (_ControllerType != "WeBusiness.Controllers." + _ControllerName + "Controller")
            {
                filterContext.Result = GetErrorResult("若继承BaseController则该控制器只能使用默认后缀Controller和命名空间只能使用WeBusiness.Controllers", null, false);
                return;
            }

            BaseAuthorizeModel auth = BaseAuthorizeHelper.GetAuthorizeModel(filterContext.HttpContext, CurrentURL);

            if (string.IsNullOrWhiteSpace(auth.GuidCode) == false)
            {
                GuidCode = auth.GuidCode;
            }

            string _loginfo = "异常退出";

            if (string.IsNullOrWhiteSpace(auth.TempDataMsg) == false)
            {
                TempData["Msg"] = auth.TempDataMsg;
                _loginfo        = auth.TempDataMsg;
            }

            if (auth.IsAuthorize == false)
            {
                //异常退出
                logType = SYSLogType.Other;
                logInfo = _loginfo;
                logUser = auth.UserName;
                //WriteSYSLog();

                filterContext.Result = GetErrorResult(auth.TempDataMsg, null, true);
            }
            else
            {
                CurrentUser = auth.CurrentSYSUser;
                logUser     = CurrentUser.UserName;
            }
        }