public static void WriteExceptionActions(ExceptionActionsModel excptionActions) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(ExceptionActionsModel)); using (TextWriter textWriter = new StreamWriter(HttpContext.Current.Server.MapPath("~/App_Data/ActionExcepted.xml"))) { xmlSerializer.Serialize(textWriter, excptionActions); } }
public static ExceptionActionsModel ReadExceptionActions() { ExceptionActionsModel exceptionActionsModel = null; XmlSerializer xmlSerializer = new XmlSerializer(typeof(ExceptionActionsModel)); using (TextReader textReader = new StreamReader(HttpContext.Current.Server.MapPath("~/App_Data/ActionExcepted.xml"))) { exceptionActionsModel = (ExceptionActionsModel)xmlSerializer.Deserialize(textReader); } return(exceptionActionsModel); }
public static bool AccessRight(string ActionName, string ControlerName, string AreaName) { string sControlerName = ControlerName != null?ControlerName.ToLower() : ""; string sActionName = ActionName != null?ActionName.ToLower() : ""; string sAreaName = string.IsNullOrEmpty(AreaName) == false?AreaName.ToLower() : "home"; if (sControlerName == "" || sActionName == "") { return(false); } //Coi thử đăng nhập chưa if (WebSecurity.IsAuthenticated) { //Kiểm tra truy cập được khai báo trong file ==> App_Data/ActionExcepted.xml ExceptionActionsModel exceptionActionsModel = ExceptionActionHelper.ReadExceptionActions(); foreach (ExceptionActionModel item in exceptionActionsModel.ExceptionActions) { if (item.ActionName.ToLower() == sActionName && (string.IsNullOrEmpty(item.ControllerName) || item.ControllerName.ToLower() == sControlerName) && (string.IsNullOrEmpty(item.AreaName) || item.AreaName.ToLower() == sAreaName)) { return(true); } } //Tiếp tục kiểm tra trong bảng phân quyền của hệ thống List <vwPage> pagesAccessRight = CacheHelper.PagesAccessRight; var ItemPagesAccessRight = pagesAccessRight.Where(x => x.ActionName.ToLowerOrEmpty() == sActionName.ToLower() && x.ControllerName.ToLowerOrEmpty() == sControlerName.ToLower() && (x.AreaName != null ? x.AreaName.ToLowerOrEmpty() == sAreaName.ToLower() : true)).FirstOrDefault(); if (ItemPagesAccessRight == null) { //Không có quyền return(false); } return(true); } else { return(false); } }