使用缓存控制用户权限类
2006-05-18 23:03
363 查看
using System;
using System.Data;
using System.Web;
using System.Web.Caching;
using TIMS.WEB.PublicClass.DataBase;
namespace TIMS.WEB.PublicClass.User
{
/*
Explain:
用户权限
*/
/// <summary>
/// 用户角色
/// </summary>
public class UserRole
{
private static string USERROLEKEY = "ROLEDIST";
private static string TABLENAME = "TM_SYS_ROLEDIST";
private static string SQL = "Select LogName, RoleName From TM_SYS_ROLEDIST";
private static string MANAROLE = "Admin";
//--------------------------------------------------------------------------------------------------------
public UserRole()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 取得角色分配
/// </summary>
/// <returns></returns>
private static DataSet GetRoleDist()
{
DataSet RoleDist = null;
if(! IsNULL())
{
RoleDist = (DataSet)HttpContext.Current.Cache[USERROLEKEY]; /* */
}
return(RoleDist);
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 判断缓存中用户信息是否存在
/// </summary>
/// <returns></returns>
private static bool IsNULL()
{
if(HttpContext.Current.Cache[USERROLEKEY] != null) /* */
{
return(false);
}
else
{
return(! LoadRoleDist());
}
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 加载角色分配
/// </summary>
/// <returns></returns>
public static bool LoadRoleDist()
{
DataSet dsRoleDist = null;
OracleDB oracleDB = new OracleDB();
try
{
dsRoleDist = oracleDB.GetDataSet(SQL,TABLENAME);
}
catch
{}
oracleDB.CloseCon();
if(dsRoleDist != null)
{
HttpContext.Current.Cache.Insert(USERROLEKEY,dsRoleDist); /* */
return(true);
}
else
{
return(false);
}
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 判断用户是否是专工
/// </summary>
/// <param name="SystemAB">true:专工;false:非专工;</param>
/// <returns>用户登录名</returns>
/// <returns>系统缩写</returns>
public static bool Power(string LogName, string RoleName)
{
string filter = "LogName = '" + LogName + "' and RoleName = '" + RoleName + "'";
DataSet RoleDist = GetRoleDist();
if(RoleDist != null)
{
DataRow [] SelRow;
SelRow = RoleDist.Tables[TABLENAME].Select(filter);
if(SelRow.Length == 1)
{
return(true);
}
else
{
return(false);
}
}
else
{
return(false);
}
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 判断用户是否是管理员
/// </summary>
/// <param name="LogName"></param>
/// <returns></returns>
public static bool IsAdmin(string LogName)
{
string filter = "LogName = '" + LogName + "' and RoleName = '" + MANAROLE + "'";
DataSet RoleDist = GetRoleDist();
if(RoleDist != null)
{
DataRow [] SelRow;
SelRow = RoleDist.Tables[TABLENAME].Select(filter);
if(SelRow.Length == 1)
{
return(true);
}
else
{
return(false);
}
}
else
{
return(false);
}
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 清空缓存
/// </summary>
/// <returns></returns>
public static bool ClearCache()
{
try
{
HttpContext.Current.Cache.Remove(USERROLEKEY); /* */
return(true);
}
catch
{
}
return(false);
}
//--------------------------------------------------------------------------------------------------------
}
}
using System.Data;
using System.Web;
using System.Web.Caching;
using TIMS.WEB.PublicClass.DataBase;
namespace TIMS.WEB.PublicClass.User
{
/*
Explain:
用户权限
*/
/// <summary>
/// 用户角色
/// </summary>
public class UserRole
{
private static string USERROLEKEY = "ROLEDIST";
private static string TABLENAME = "TM_SYS_ROLEDIST";
private static string SQL = "Select LogName, RoleName From TM_SYS_ROLEDIST";
private static string MANAROLE = "Admin";
//--------------------------------------------------------------------------------------------------------
public UserRole()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 取得角色分配
/// </summary>
/// <returns></returns>
private static DataSet GetRoleDist()
{
DataSet RoleDist = null;
if(! IsNULL())
{
RoleDist = (DataSet)HttpContext.Current.Cache[USERROLEKEY]; /* */
}
return(RoleDist);
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 判断缓存中用户信息是否存在
/// </summary>
/// <returns></returns>
private static bool IsNULL()
{
if(HttpContext.Current.Cache[USERROLEKEY] != null) /* */
{
return(false);
}
else
{
return(! LoadRoleDist());
}
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 加载角色分配
/// </summary>
/// <returns></returns>
public static bool LoadRoleDist()
{
DataSet dsRoleDist = null;
OracleDB oracleDB = new OracleDB();
try
{
dsRoleDist = oracleDB.GetDataSet(SQL,TABLENAME);
}
catch
{}
oracleDB.CloseCon();
if(dsRoleDist != null)
{
HttpContext.Current.Cache.Insert(USERROLEKEY,dsRoleDist); /* */
return(true);
}
else
{
return(false);
}
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 判断用户是否是专工
/// </summary>
/// <param name="SystemAB">true:专工;false:非专工;</param>
/// <returns>用户登录名</returns>
/// <returns>系统缩写</returns>
public static bool Power(string LogName, string RoleName)
{
string filter = "LogName = '" + LogName + "' and RoleName = '" + RoleName + "'";
DataSet RoleDist = GetRoleDist();
if(RoleDist != null)
{
DataRow [] SelRow;
SelRow = RoleDist.Tables[TABLENAME].Select(filter);
if(SelRow.Length == 1)
{
return(true);
}
else
{
return(false);
}
}
else
{
return(false);
}
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 判断用户是否是管理员
/// </summary>
/// <param name="LogName"></param>
/// <returns></returns>
public static bool IsAdmin(string LogName)
{
string filter = "LogName = '" + LogName + "' and RoleName = '" + MANAROLE + "'";
DataSet RoleDist = GetRoleDist();
if(RoleDist != null)
{
DataRow [] SelRow;
SelRow = RoleDist.Tables[TABLENAME].Select(filter);
if(SelRow.Length == 1)
{
return(true);
}
else
{
return(false);
}
}
else
{
return(false);
}
}
//--------------------------------------------------------------------------------------------------------
/// <summary>
/// 清空缓存
/// </summary>
/// <returns></returns>
public static bool ClearCache()
{
try
{
HttpContext.Current.Cache.Remove(USERROLEKEY); /* */
return(true);
}
catch
{
}
return(false);
}
//--------------------------------------------------------------------------------------------------------
}
}
相关文章推荐
- 使用su/sudo控制用户权限
- Sudo控制普通用户使用命令的权限
- 使用JavaEE的ServerAuthModule模块和web.xml进行相应配置,实现对用户的权限控制
- 第三十一天 MySQL并发控制、存储引擎介绍、用户权限管理、缓存管理和数据类型选择
- Yii中使用RBAC完全指南 (用户角色权限控制)
- 开始VS 2012中LightSwitch系列的第5部分:我可以使用用户权限来控制访问权吗?
- 浅析Yii中使用RBAC的完全指南(用户角色权限控制)
- 使用Lync 2013 基于角色的权限控制:RBAC 给用户分配指定的操作权限
- struts2如何使用拦截器进行用户权限控制实例
- LINUX——gitlab版本控制,关于项目组管理,项目用户及权限管理的使用
- Linux下使用ACL命令实现控制用户的目录访问权限
- 使用Zend_Auth和Zend_Acl进行登录认证及根据用户角色进行权限控制
- Yii中使用RBAC完全指南 (用户角色权限控制)
- mongodb 用户身份验证,权限控制db.createUser()方法使用
- 使用Filter控制用户登录权限
- 使用JavaEE的ServerAuthModule模块和web.xml进行相应配置,实现对用户的权限控制
- struts2如何使用拦截器进行用户权限控制
- 利用sudo控制用户对系统命令的使用权限
- 浅析Yii中使用RBAC的完全指南(用户角色权限控制)
- restlet2.1 学习笔记(十一)为用户分配角色,并使用角色控制权限。