Datatable转换为List(用户权限验证)
来源:互联网 发布:手机淘宝怎么找客服 编辑:程序博客网 时间:2024/06/04 01:18
//将string转换为List<int>List<int> lookList = new List<int>(); //保存用户对应的可查看模块id string modelIds = data.Tables[0].Rows[0][1].ToString();//1,2,3,4,5形式的string string[] lookModelIds = modelIds.Split(myChar);//char[] myChar = { ',' }; for (int i = 0; i < lookModelIds.Length; i++) { if (!string.IsNullOrEmpty(lookModelIds[i])) { lookList.Add(Convert.ToInt32(lookModelIds[i])); } }HttpContext.Current.Session.Add(MODEL_LIST, lookList);//将用户对应的可查看模块id保存到session
用于验证登陆用户是否具有权限:
/// <summary>/// 验证权限。/// </summary>/// <param name="level">权限级别</param>/// <param name="model">模块</param>/// <returns></returns>protected bool VerifyUserRight(CommonEnum.PermissionLevel level, CommonEnum.ModelType model){bool haveRight = false;if (level == CommonEnum.PermissionLevel.View){haveRight = LoginHelper.SessionUserModelList.Contains((int)model);//model为菜单id,}else if (level == CommonEnum.PermissionLevel.Edit){haveRight = LoginHelper.SessionAllowEditModelList.Contains((int)model);}return haveRight;}
SessionUserModelList实现如下:
<span style="white-space:pre"></span>/// <summary> /// 获得登录用户可查看模块list /// </summary> public static List<int> SessionUserModelList { get { List<int> list = HttpContext.Current.Session[MODEL_LIST] as List<int>; if (list == null) { HttpContext.Current.Response.Redirect("/out.aspx"); } return list; } }
//将datatable转换为List List<object> list = new List<object>(); foreach (DataRow dr in dt.Rows)//将datatable转换为List { list.Add(new { id = dr["devicecode"].ToString(), name = dr["devicecode"].ToString() }); }
0 0
- Datatable转换为List(用户权限验证)
- datatable转换为list
- DataTable转换为List
- DataTable转换为List
- DataTable 转换为 List
- datatable转换为list
- DataTable 转换为 List ?
- List<T>转换为DataTable
- 将list 转换为 datatable
- List<T>转换为DataTable
- List<T>转换为DataTable
- 将List转换为DataTable
- List<T>转换为DataTable
- .net DataTable 转换为 List
- List<T>转换为DataTable
- List<T>转换为DataTable
- 通用的DataTable转换为List
- DataTable转换为List的通用类
- 关于Java 中 static{}此写法说明
- Centos下yum安装heartbeat
- google protobuf学习笔记一:windows下环境配置
- UVa 11342 - Three-square
- iOS BUG收集: -[__NSCFNumber rangeOfCharacterFromSet:]: unrecognized selector sent to instance
- Datatable转换为List(用户权限验证)
- NSRunLoop
- mybatis的批量新增
- 3.网络代理组件
- 前端开发工具-webstorm及其他工具
- Ubuntu下配置samba实现文件夹共享
- bootstrap表单学习笔记3-1
- Winform窗体传值
- PHP将JSON转为XML