public override void OnActionExecuting(ActionExecutingContext filterContext) { //base.OnActionExecuting(filterContext); string ActionName = filterContext.ActionDescriptor.ActionName.ToLower(); string Url = filterContext.HttpContext.Request.CurrentExecutionFilePath.Trim('/').Split('/')[0] + ""; string id = Common.Security.DESDecrypt(filterContext.HttpContext.Request.Cookies["account"].Values["id"].ToString()); Model.Account account = new BLL.Account().GetModel(int.Parse(id)); DataRow[] menu = DbHelperSQL.QueryDT("select * from RoleList" + " inner join Menu on Menu.Id=RoleList.Menuid where roleid=" + account.RoleId).Select("url like '%" + Url + "%'"); //DataRow[] menu = ((DataTable)filterContext.HttpContext.Session["Role"]).Select("url like '%" + Url + "%'"); if (menu.Length > 0) { //增加权限 if (ActionName == "add" && menu[0]["Add"].ToString() == "1") { } else if (ActionName == "edit" && menu[0]["Edit"].ToString() == "1") { } else if (ActionName == "del" && menu[0]["Del"].ToString() == "1") { } else if (ActionName == "show" && menu[0]["Show"].ToString() == "1") { } else if (ActionName == "list") { } else if (ActionName == "index") { filterContext.Controller.ViewBag.Add = menu[0]["Add"].ToString() == "1" ? true : false; filterContext.Controller.ViewBag.Edit = menu[0]["Edit"].ToString() == "1" ? true : false; filterContext.Controller.ViewBag.Del = menu[0]["Del"].ToString() == "1" ? true : false; filterContext.Controller.ViewBag.Show = menu[0]["Show"].ToString() == "1" ? true : false; } else { filterContext.Result = new ContentResult() { Content = "{success=-1,msg=\"无权限\"}", ContentType = "application/json" }; } } else { filterContext.Result = new ContentResult() { Content = "无权限" }; } }
public override void OnAuthorization(AuthorizationContext filterContext) { //base.OnAuthorization(filterContext); try { string id = Common.Security.DESDecrypt(filterContext.HttpContext.Request.Cookies["account"].Values["id"].ToString()); Model.Account account = new BLL.Account().GetModel(int.Parse(id)); if (account != null) { } else { filterContext.Result = new RedirectResult("/main/login"); } } catch { filterContext.Result = new RedirectResult("/main/login"); } }
public ActionResult Menu() { string id = Common.Security.DESDecrypt(Request.Cookies["account"].Values["id"].ToString()); Model.Account account = new BLL.Account().GetModel(int.Parse(id)); DataTable menu = DbHelperSQL.QueryDT("select * from RoleList" + " inner join Menu on Menu.Id=RoleList.menuid where roleid=" + account.RoleId); StringBuilder sb = new StringBuilder(); sb.Append("{\"menu\":["); int count = 0; foreach (DataRow r in menu.Select("parentid=0", "order asc")) { if (count > 0) { sb.Append(","); } sb.Append("{\"menu\":\"" + r["menuname"] + "\",\"img\":\"" + r["img"] + "\",\"url\":\"" + r["url"] + "\",\"data\":["); int scount = 0; foreach (DataRow sr in menu.Select("parentid=" + r["id"], "order asc")) { if (scount > 0) { sb.Append(","); } sb.Append("{\"menu\":\"" + sr["menuname"] + "\",\"img\":\"" + sr["img"] + "\",\"url\":\"" + sr["url"] + "\"}"); } sb.Append("]}"); count++; } sb.Append("]}"); return(Content(sb.ToString())); }
public ActionResult Login(string UserName, string UserPwd) { Model.Account ac = new BLL.Account().Login(UserName, Common.Security.Md5Hash(UserPwd), "0,1"); if (ac != null) { WebCookie.AddCookie(ac.Id.ToString(), ac.AccountName, ac.AType.ToString(), ac.CompanyId.ToString());//存cookie var result = new { success = 0, msg = "登录成功" }; return(Json(result)); } else { var result = new { success = 1, msg = "登录失败" }; return(Json(result)); } }