//找到Role对某个模块有无权限 public CRMRoleModule GetRoleAccessRight(long RoleID, enumModule Module) { var qry = from t in CRMRoleModules where t.RoleID == RoleID && t.ModuleID == (long)Module select t; return(qry.FirstOrDefault()); }
//找到Role对某个模块有无权限 public CRMRoleModule GetRoleAccessRight(long RoleID, enumModule Module) { var qry = from t in CRMRoleModules where t.RoleID == RoleID && t.ModuleID == (long)Module select t; return qry.FirstOrDefault(); }
public void Authentication(enumModule Module, params Button[] SaveButtons) { if (Session[Session_ID] == null) { ShowMessage(GetREMes("MsgSessionTimeOut")); FormsAuthentication.RedirectToLoginPage(); //Response.Write("<script>parent.window.location.href='../Login.aspx'</script>"); Response.End(); return; } else { /* 获取客户端的用户在线标识Guid * 如果标识Guid与服务端不一致,则重定向到重复登录页面 */ string m_strUserOnlineID = CookieHelper.GetCookie("UserOnlineID").Value; if (!string.IsNullOrEmpty(m_strUserOnlineID)) { Dictionary <string, string> userlist = Application["OnlineUserList"] as Dictionary <string, string>; if (m_strUserOnlineID != userlist[LoginUserName]) { FormsAuthentication.RedirectToLoginPage(); } } /******** End *******/ //Check Login User's role has right on specific module? BaseService svr = new BaseService(); var rights = svr.GetRoleAccessRight(LoginUserRoleID, Module); if (rights == null || !rights.ReadOnly && !rights.New && !rights.Edit && !rights.Del) { Response.Redirect("~/AccessDeny.aspx"); return; } else { Button btnNew, btnDel, btnSave; if (this.Master != null) { btnNew = (Button)this.Master.FindControl("CPH1").FindControl("btnNew"); btnDel = (Button)this.Master.FindControl("CPH1").FindControl("btnDel"); btnSave = (Button)this.Master.FindControl("CPH1").FindControl("btnSave"); } else { btnNew = (Button)this.FindControl("btnNew"); btnDel = (Button)this.FindControl("btnDel"); btnSave = (Button)this.FindControl("btnSave"); } if (!rights.New) { if (btnNew != null) { btnNew.Enabled = false; } } if (!rights.Del) { if (btnDel != null) { btnDel.Enabled = false; } } if (string.IsNullOrEmpty(Request["id"])) { return; } int id = Convert.ToInt32(Request["id"]); //例如客户信息,销售录入后,是不能更改的,所以要区分新增和修改的权利 //id=0& New=false, id>0 & Edit=false if ((!rights.Edit && id > 0) || (!rights.New && id == 0)) { if (btnSave != null) { btnSave.Enabled = false; } foreach (var item in SaveButtons) { item.Enabled = false; } } } } }
public void Authentication(enumModule Module,params Button[] SaveButtons) { if (Session[Session_ID] == null) { ShowMessage(GetREMes("MsgSessionTimeOut")); FormsAuthentication.RedirectToLoginPage(); //Response.Write("<script>parent.window.location.href='../Login.aspx'</script>"); Response.End(); return; } else { /* 获取客户端的用户在线标识Guid * 如果标识Guid与服务端不一致,则重定向到重复登录页面 */ string m_strUserOnlineID = CookieHelper.GetCookie("UserOnlineID").Value; if (!string.IsNullOrEmpty(m_strUserOnlineID)) { Dictionary<string, string> userlist = Application["OnlineUserList"] as Dictionary<string, string>; if (m_strUserOnlineID != userlist[LoginUserName]) { FormsAuthentication.RedirectToLoginPage(); } } /******** End *******/ //Check Login User's role has right on specific module? BaseService svr = new BaseService(); var rights =svr.GetRoleAccessRight(LoginUserRoleID, Module); if (rights==null||!rights.ReadOnly && !rights.New && !rights.Edit && !rights.Del) { Response.Redirect("~/AccessDeny.aspx"); return; } else { Button btnNew, btnDel, btnSave; if (this.Master != null) { btnNew = (Button)this.Master.FindControl("CPH1").FindControl("btnNew"); btnDel = (Button)this.Master.FindControl("CPH1").FindControl("btnDel"); btnSave = (Button)this.Master.FindControl("CPH1").FindControl("btnSave"); } else { btnNew = (Button)this.FindControl("btnNew"); btnDel = (Button)this.FindControl("btnDel"); btnSave = (Button)this.FindControl("btnSave"); } if (!rights.New) { if (btnNew != null) btnNew.Enabled = false; } if (!rights.Del) { if (btnDel != null) btnDel.Enabled = false; } if (string.IsNullOrEmpty(Request["id"])) return; int id = Convert.ToInt32(Request["id"]); //例如客户信息,销售录入后,是不能更改的,所以要区分新增和修改的权利 //id=0& New=false, id>0 & Edit=false if ((!rights.Edit && id > 0) || (!rights.New && id == 0)) { if (btnSave != null) btnSave.Enabled = false; foreach (var item in SaveButtons) { item.Enabled = false; } } } } }