예제 #1
0
        protected void Application_Error(object sender, EventArgs e)
        {
            var errorLogPath = Server.MapPath("/TempFile/ErrorLogPath");
            var errorPage = "/CustomPage/error.html";
            Exception ex = null;
            try
            {
                ex = Server.GetLastError().GetBaseException();

                var sysSettingEntity = new SysGlobalSettingBiz().GetSysSettingEntity();
                errorLogPath = Server.MapPath(sysSettingEntity.ErrorLogPath);
                errorPage = sysSettingEntity.ErrorPage;

                BcUserInfoEntity userInfo = null;
                var identity = HttpContext.Current.User.Identity as FormsIdentity;
                if (identity != null)
                    userInfo = new BcUserInfoBiz().GetBcUserInfoWithPermission(identity.Ticket.UserData);

                var entity = new BcLogErrorEntity();
                if (userInfo != null)
                {
                    entity.UserId = userInfo.UserId;
                    entity.UserName = userInfo.UserName;
                }
                else
                {
                    entity.UserId = 0;
                    entity.UserName = "";
                }
                entity.OpUrl = Request.Url.ToString();
                entity.OpTime = DateTime.Now;
                entity.OpHostAddress = Request.UserHostAddress;
                entity.OpHostName = Request.UserHostName;
                entity.OpUserAgent = Request.UserAgent;
                entity.OpQueryString = Request.QueryString.ToString();
                entity.OpHttpMethod = Request.HttpMethod;
                entity.Message = ex.ToString();

                try
                {
                    new BcLogErrorBiz().AddNewBcLogError(entity);
                }
                catch (Exception ex2)
                {
                    WriteLocalLog(errorLogPath, ex.ToString());
                    WriteLocalLog(errorLogPath, ex2.ToString());
                }
            }
            catch (Exception ex3)
            {
                if (ex != null) WriteLocalLog(errorLogPath, ex.ToString());
                WriteLocalLog(errorLogPath, ex3.ToString());
            }
            finally
            {
                if (!ConfigHelper.GetConfigBool("IsDevelopMode"))
                {
                    Server.ClearError();
                    Response.Redirect(errorPage);
                }
            }
        }
예제 #2
0
        protected void submit_Click(object sender, EventArgs e)
        {
            var usId = name.Text.Trim();
            var pswd = password.Text.Trim();

            if (string.IsNullOrEmpty(usId))
            {
                ShowErrorMsg("登录失败,用户名不能为空!");
                return;
            }

            if (string.IsNullOrEmpty(pswd))
            {
                ShowErrorMsg("登录失败,密码不能为空!");
                return;
            }

            Session.Clear();

            Response.Cookies["webfwu"].Value = usId;
            Response.Cookies["webfwu"].Expires = DateTime.Now.AddMonths(2);

            if (remember.Checked)
            {
                Response.Cookies["webfwp"].Value = pswd;
                Response.Cookies["webfwp"].Expires = DateTime.Now.AddMonths(2);
            }
            else
            {
                Response.Cookies["webfwp"].Value = "";
            }

            var uiBiz = new BcUserInfoBiz();
            var result = uiBiz.DoLogin(usId, pswd);
            switch (result)
            {
                case LoginStatusEnum.Success:
                    FormsAuthentication.SetAuthCookie(usId, false);
                    //登陆成功,把用户编号保存到票据中    
                    var ticket = new FormsAuthenticationTicket(1, usId, DateTime.Now, DateTime.Now.AddMonths(2), false,
                        usId, FormsAuthentication.FormsCookiePath);
                    var encTicket = FormsAuthentication.Encrypt(ticket);
                    var newCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
                    HttpContext.Current.Response.Cookies.Add(newCookie);
                    //登陆成功,跳转到首页
                    Response.Redirect(ReturnUrl);
                    break;
                case LoginStatusEnum.PasswordError:
                    ShowErrorMsg("登录失败,密码错误!");
                    break;
                case LoginStatusEnum.UserNotExist:
                    ShowErrorMsg("登录失败,用户名不存在!");
                    break;
                case LoginStatusEnum.UserDisabled:
                    ShowErrorMsg("登录失败,用户被禁用!");
                    break;
                default:
                    ShowErrorMsg("登录失败,请重试!");
                    break;
            }
        }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="permissionType">1=角色权限,2=用户权限</param>
        /// <param name="userRoleId"></param>
        public List<BcPermissionEntity> GetEnabledBcPermissionList(int? permissionType, int? userRoleId = 0)
        {
            //获取可用的权限列表
            var allBcPermissionList = EntityExecution.SelectAll<BcPermissionEntity>();
            var enabledBcPermissionList = new List<BcPermissionEntity>();
            if (userRoleId == 0)
            {
                enabledBcPermissionList.AddRange(allBcPermissionList.Where(n =>
                    n.PermissionType == permissionType));
            }
            else
            {
                enabledBcPermissionList.AddRange(allBcPermissionList.Where(n =>
                    n.UserRoleId == userRoleId && n.PermissionType == permissionType));
            }

            //加载可用的菜单列表
            var listEnabledSysMenuEntity = new SysMenuBiz().GetEnabledSysMenuList();

            //根据可用的菜单列表,去掉没有起到作用的功能点
            for (int i = enabledBcPermissionList.Count - 1; i >= 0; i--)
            {
                var permisionEntity = enabledBcPermissionList[i];
                var list =
                    listEnabledSysMenuEntity.Where(
                        n => n.ModuleId == permisionEntity.ModuleId && n.FuncPointId == permisionEntity.FuncPointId)
                        .ToList();
                if (list.Count <= 0) enabledBcPermissionList.Remove(permisionEntity);
            }

            //补充所有id的name
            var allBcRoleList = new BcRoleBiz().GetBcRoleList();
            var allBcUserInfoList = new BcUserInfoBiz().GetBcUserInfoList();

            foreach (BcPermissionEntity bcPermissionEntity in enabledBcPermissionList)
            {
                bcPermissionEntity.ModuleName =
                    SysEnumNameExBiz.GetDescription<SysModuleEnum>(bcPermissionEntity.ModuleId);
                bcPermissionEntity.FuncPointName =
                    SysEnumNameExBiz.GetDescription<SysFuncPointEnum>(bcPermissionEntity.FuncPointId);
                if (permissionType == 1)
                {
                    var list = allBcRoleList.Where(n => n.RoleId == bcPermissionEntity.UserRoleId).ToList();
                    if (list.Count > 0) bcPermissionEntity.UserRoleName = list[0].RoleName;
                }
                else if (permissionType == 2)
                {
                    var list = allBcUserInfoList.Where(n => n.UserId == bcPermissionEntity.UserRoleId).ToList();
                    if (list.Count > 0) bcPermissionEntity.UserRoleName = list[0].UserName;
                }

                if (!string.IsNullOrEmpty(bcPermissionEntity.Permissions))
                {
                    bcPermissionEntity.PermissionList = new List<string>();
                    bcPermissionEntity.PermissionNameList = new List<string>();
                    var list = bcPermissionEntity.Permissions.Split(',').ToList();
                    foreach (string s in list)
                    {
                        if (!string.IsNullOrEmpty(s))
                        {
                            bcPermissionEntity.PermissionList.Add(s);
                            bcPermissionEntity.PermissionNameList.Add(
                                SysEnumNameExBiz.GetDescription<SysFuncPointEnum>(s));
                        }
                    }
                    if (bcPermissionEntity.PermissionNameList.Count > 0)
                        bcPermissionEntity.PermissionNames = string.Join(",",
                            bcPermissionEntity.PermissionNameList.ToArray());
                }
            }
            return
                enabledBcPermissionList.OrderBy(n => n.UserRoleId)
                    .ThenBy(n => n.ModuleId)
                    .ThenBy(n => n.FuncPointId)
                    .ToList();
        }
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="permissionType">1=角色权限,2=用户权限</param>
        /// <param name="userRoleId"></param>
        public List <BcPermissionEntity> GetEnabledBcPermissionList(int?permissionType, int?userRoleId = 0)
        {
            //获取可用的权限列表
            var allBcPermissionList     = EntityExecution.SelectAll <BcPermissionEntity>();
            var enabledBcPermissionList = new List <BcPermissionEntity>();

            if (userRoleId == 0)
            {
                enabledBcPermissionList.AddRange(allBcPermissionList.Where(n =>
                                                                           n.PermissionType == permissionType));
            }
            else
            {
                enabledBcPermissionList.AddRange(allBcPermissionList.Where(n =>
                                                                           n.UserRoleId == userRoleId && n.PermissionType == permissionType));
            }

            //加载可用的菜单列表
            var listEnabledSysMenuEntity = new SysMenuBiz().GetEnabledSysMenuList();

            //根据可用的菜单列表,去掉没有起到作用的功能点
            for (int i = enabledBcPermissionList.Count - 1; i >= 0; i--)
            {
                var permisionEntity = enabledBcPermissionList[i];
                var list            =
                    listEnabledSysMenuEntity.Where(
                        n => n.ModuleId == permisionEntity.ModuleId && n.FuncPointId == permisionEntity.FuncPointId)
                    .ToList();
                if (list.Count <= 0)
                {
                    enabledBcPermissionList.Remove(permisionEntity);
                }
            }

            //补充所有id的name
            var allBcRoleList     = new BcRoleBiz().GetBcRoleList();
            var allBcUserInfoList = new BcUserInfoBiz().GetBcUserInfoList();

            foreach (BcPermissionEntity bcPermissionEntity in enabledBcPermissionList)
            {
                bcPermissionEntity.ModuleName =
                    SysEnumNameExBiz.GetDescription <SysModuleEnum>(bcPermissionEntity.ModuleId);
                bcPermissionEntity.FuncPointName =
                    SysEnumNameExBiz.GetDescription <SysFuncPointEnum>(bcPermissionEntity.FuncPointId);
                if (permissionType == 1)
                {
                    var list = allBcRoleList.Where(n => n.RoleId == bcPermissionEntity.UserRoleId).ToList();
                    if (list.Count > 0)
                    {
                        bcPermissionEntity.UserRoleName = list[0].RoleName;
                    }
                }
                else if (permissionType == 2)
                {
                    var list = allBcUserInfoList.Where(n => n.UserId == bcPermissionEntity.UserRoleId).ToList();
                    if (list.Count > 0)
                    {
                        bcPermissionEntity.UserRoleName = list[0].UserName;
                    }
                }

                if (!string.IsNullOrEmpty(bcPermissionEntity.Permissions))
                {
                    bcPermissionEntity.PermissionList     = new List <string>();
                    bcPermissionEntity.PermissionNameList = new List <string>();
                    var list = bcPermissionEntity.Permissions.Split(',').ToList();
                    foreach (string s in list)
                    {
                        if (!string.IsNullOrEmpty(s))
                        {
                            bcPermissionEntity.PermissionList.Add(s);
                            bcPermissionEntity.PermissionNameList.Add(
                                SysEnumNameExBiz.GetDescription <SysFuncPointEnum>(s));
                        }
                    }
                    if (bcPermissionEntity.PermissionNameList.Count > 0)
                    {
                        bcPermissionEntity.PermissionNames = string.Join(",",
                                                                         bcPermissionEntity.PermissionNameList.ToArray());
                    }
                }
            }
            return
                (enabledBcPermissionList.OrderBy(n => n.UserRoleId)
                 .ThenBy(n => n.ModuleId)
                 .ThenBy(n => n.FuncPointId)
                 .ToList());
        }