Example #1
0
        public static void ResetCache()
        {
            var cache = WindsorContaineFactory.GetContainer().Resolve <ICache>();

            cache.RemoveApplicationCache(CacheAllPermission);
            GetAllPermission();
        }
Example #2
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            if (filterContext.Exception != null)
            {
                ILog log = WindsorContaineFactory.GetContainer().Resolve <ILog>();

                var       controllerName = filterContext.RouteData.Values["controller"].ToString();
                var       actionName     = filterContext.ActionDescriptor.ActionName;
                LogEntity logEnt         = new LogEntity()
                {
                    ClassName  = controllerName,
                    MethodName = actionName,
                    Level      = LogLevel.ERROR,
                    LogDetail  = filterContext.Exception.Message + '|' + filterContext.Exception.StackTrace
                };
                log.WriteLog(LogEnum.LogWebUI, logEnt);


                var attrs = filterContext.ActionDescriptor.GetCustomAttributes(typeof(AuthViewPageAttribute), true);
                // 是页面请求才处理
                if (attrs.Length > 0)
                {
                    string msgTmp;
                    if (filterContext.Exception is JsMiracleException)//已知异常 ,就不出详细异常信息了
                    {
                        msgTmp = @"<script type=""text/javascript"">
                                                    $.messager.alert('系统错误','<b>系统错误</b><br/>{0}','error');
                                                </script>";
                    }
                    else
                    {
                        msgTmp = @"<script type=""text/javascript"">
                                                    $.messager.alert('未知错误','<b>异常消息:</b>{0}</p><b>触发Action:</b>{1}</p><b>异常类型:</b>{2}','error');
                                                </script>";
                    }


                    var excResult = new ContentResult();
                    excResult.Content = string.Format(msgTmp
                                                      , filterContext.Exception.GetBaseException().Message
                                                      , filterContext.ActionDescriptor.ActionName
                                                      , filterContext.Exception.GetBaseException().GetType().ToString());

                    filterContext.Result = excResult;

                    filterContext.ExceptionHandled = true;
                    return;
                }
            }

            base.OnActionExecuted(filterContext);
        }
Example #3
0
        //private readonly ICache cache;
        //private readonly IPermission dalPermission;

        //public ActionPermission(ICache repoCache, IPermission repoPermission)
        //{
        //    cache = repoCache;
        //    dalPermission = repoPermission;
        //}

        //public IList<ActionPermission> GetAllActionPermissions()
        //{
        //    if (cache.GetApplicationCache("actionpermission") == null)
        //    {
        //        cache.SetApplicationCache("actionpermission", base.GetAll());
        //    }
        //    return (IList<ActionPermission>)cache.GetApplicationCache("actionpermission");
        //}

        public static PermissionViewModule GetAllPermission()
        {
            var cache = WindsorContaineFactory.GetContainer().Resolve <ICache>();

            if (cache.GetApplicationCache(CacheAllPermission) == null)
            {
                var dalPermission = WindsorContaineFactory.GetContainer().Resolve <IPermission>();

                var allPer = dalPermission.GetAllPermission();
                cache.SetApplicationCache(CacheAllPermission, dalPermission.GetAllPermission());
            }
            return((PermissionViewModule)cache.GetApplicationCache(CacheAllPermission));
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            //API注入包
            var controllerFactory = new WindsorControllerFactory(WindsorContaineFactory.GetContainer().Kernel);

            ControllerBuilder.Current.SetControllerFactory(controllerFactory);
        }
Example #5
0
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            base.HandleUnauthorizedRequest(filterContext);

            if (isAuthViewPage)
            {
                var wcFactory = WindsorContaineFactory.GetContainer();
                var formAuth  = wcFactory.Resolve <IFormsAuthentication>();
                var cache     = wcFactory.Resolve <ICache>();

                // 当前用户登出
                formAuth.SignOut();
                cache.RemoveSessionCache(HttpContext.Current.User.Identity.Name);

                //filterContext.Result = new RedirectResult("/Account/LogIn");
                //filterContext.Result = new HttpUnauthorizedResult();

                string msg = string.Format(
                    @"<script type=""text/javascript"">
                            window.location = '{0}'
                      </script>", "/Account/LogIn");

                filterContext.Result = new ContentResult {
                    Content = msg
                };
            }
            else
            {
                string msg = string.Format(@"
                                <script type=""text/javascript"">
                                 $.messager.alert('权限错误','抱歉,你不具有当前操作的权限!controller:{0},action:{1}');
                                </script>", controllerName, actionName);

                //filterContext.Result = new ContentResult { Content = msg };

                filterContext.Result = new ContentResult {
                    Content = msg
                };


                //filterContext.Result = new JsonResult()
                //{
                //    Data = ret
                //};
            }
        }
        public static CurrentUser GetCurrentUser()
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated && !IsAdmin)
            {
                throw new JsMiracleException("用户未登录");//必须要用户Form验证后才能使用CurrentUser
            }
            string userid = HttpContext.Current.User.Identity.Name;
            var    cache  = WindsorContaineFactory.GetContainer().Resolve <ICache>();

            if (cache.GetSessionCache(userid) == null)
            {
                // 成功用户的操作
                if (HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    CurrentUser cu   = new CurrentUser();
                    var         user = WindsorContaineFactory.GetContainer().Resolve <IUser>();
                    cu.UserInfo = user.GetEntityByYHBH(HttpContext.Current.User.Identity.Name);
                    var per = WindsorContaineFactory.GetContainer().Resolve <IPermission>();
                    cu.Permissions = per.GetPermissionListByUserID(userid);
                    cache.SetSessionCache(userid, cu);
                }
                else if (IsAdmin)
                {
                    // 管理员的操作
                    userid = "admin";
                    CurrentUser cu = new CurrentUser();
                    cu.UserInfo = new IMS_UP_YH()
                    {
                        YHID = "admin", YHM = "admin"
                    };

                    cu.Permissions = ActionPermission.GetAllPermission();
                    cache.SetSessionCache(userid, cu);
                }
            }

            return((CurrentUser)cache.GetSessionCache(userid));
        }