Esempio n. 1
0
        /// <summary>
        /// 是否是超级管理员
        /// </summary>
        /// <returns></returns>
        public static bool IsSAdmin()
        {
            var admin = AdminPageStatic.GetLoginUserInfo();

            if (admin != null && admin.GID == -1)
            {
                return(true);
            }
            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// 当前用户在当前页面的访问权限验证,并返回页面的操作权限(如果有页面访问权限则返回类似"1110011"的权限表达式,如果没访问权限则返回null)
        /// </summary>
        /// <returns></returns>
        public static string CurrPageRoleCheck()
        {
            string rightExp = null;

            const string cacheKey = "CurrPageRight";

            if (HttpContext.Current.Items.Contains(cacheKey))
            {
                //已经在请求周期中缓存了
                rightExp = HttpContext.Current.Items[cacheKey].GetString(null);
            }
            else
            {
                //当前请求周期中未缓存

                //当前登录用户
                var adminInfo = AdminPageStatic.GetLoginUserInfo(false);

                if (adminInfo != null)
                {
                    //必须已登录

                    //如果有登录且是超级管理员,则直接放行,并拥有完全操作权限
                    if (adminInfo.GID == -1)
                    {
                        rightExp = _pageAllRightExp;
                    }
                    else
                    {
                        var    currUrlPath     = GetCurrPagePath();
                        string noRoleToUrlPath = "";//没权限需要跳转到的地址

                        if (InNoRolePage(currUrlPath, out noRoleToUrlPath))
                        {
                            //如果页面在排除权限验证页面配置中,则直接放行,并拥有完全操作权限
                            rightExp = _pageAllRightExp;
                        }
                        else
                        {
                            //获取当前管理员对当前页面的操作权限(或是无访问权限)
                            rightExp = (adminInfo == null ? null : GetAdminRightExpByPageURL(adminInfo.AID, adminInfo.GID, currUrlPath));

                            if (rightExp == null)
                            {
                                HttpContext.Current.Response.Redirect(HttpContext.Current.Request.GetApplicationURL().GetUrlRelativePath(noRoleToUrlPath), true);
                            }
                        }
                    }
                }

                HttpContext.Current.Items[cacheKey] = rightExp;
            }

            return(rightExp);
        }
Esempio n. 3
0
        /// <summary>
        /// 获得当前登录后台的用户名
        /// </summary>
        /// <returns></returns>
        public static string GetCurrUserName()
        {
            var admin = AdminPageStatic.GetLoginUserInfo();

            return(admin == null ? "" : admin.AName);
        }