public JsonResult UpdateRoute() { List <Models.ModelRoute> route_list = new List <Models.ModelRoute>(); #region 反射获取所有的控制路由 string path = IOHelper.GetMapPath("~/bin/Universal.Web.dll"); byte[] buffer = System.IO.File.ReadAllBytes(path); Assembly assembly = Assembly.Load(buffer); foreach (var type in assembly.ExportedTypes) { System.Reflection.MemberInfo[] properties = type.GetMembers(); foreach (var item in properties) { string controllerName = item.ReflectedType.Name.Replace("Controller", "").ToString(); string actionName = item.Name.ToString(); //访问路由 string route_map = controllerName.ToLower() + "/" + actionName.ToLower(); //是否是HttpPost请求 bool IsHttpPost = item.GetCustomAttributes(typeof(System.Web.Mvc.HttpPostAttribute), true).Count() > 0 ? true : false; object[] attrs = item.GetCustomAttributes(typeof(Framework.AdminPermissionAttribute), true); if (attrs.Length == 1) { Framework.AdminPermissionAttribute attr = (Framework.AdminPermissionAttribute)attrs[0]; route_list.Add(new Models.ModelRoute { Tag = attr.Tag, Desc = attr.Desc, IsPost = IsHttpPost, Route = route_map }); } } } #endregion BLL.BaseBLL <Entity.SysRoute> bll = new BLL.BaseBLL <Entity.SysRoute>(); var db_list = bll.GetListBy(0, new List <BLL.FilterSearch>(), null); foreach (var item in db_list) { var entity = route_list.Where(p => p.IsPost == item.IsPost && p.Route == item.Route).FirstOrDefault(); //如果数据库对应程序中不存在,则删除数据库里的 if (entity == null) { bll.Del(item); } else { //否则修改数据库里的DES之类的辅助说明 item.Desc = entity.Desc; item.Tag = entity.Tag; bll.Modify(item); } } foreach (var item in route_list) { var entity = bll.GetModel(p => p.IsPost == item.IsPost && p.Route == item.Route, null); if (entity == null) { var route = new Entity.SysRoute(); route.AddTime = DateTime.Now; route.Desc = item.Desc; route.IsPost = item.IsPost; route.Route = item.Route; route.Tag = item.Tag; bll.Add(route); } } AddAdminLogs(Entity.SysLogMethodType.Update, "更新权限数据"); WorkContext.AjaxStringEntity.msg = 1; WorkContext.AjaxStringEntity.msgbox = "success"; return(Json(WorkContext.AjaxStringEntity)); }