用于读、写、删除、比较Session中的用户信息的类库。
?/// <summary>
??? /// 用于讀、寫、刪除、比較Session中的用戶信息。
??? /// </summary>
??? [Serializable]
??? public class SessionBox
??? {
??????? private SessionBox() { }
??????? #region 用戶Session操作
??????? /// <summary>
??????? /// 檢測User Session是否存在
??????? /// </summary>
??????? /// <returns></returns>
??????? public static bool CheckUserSession()
??????? {
??????????? object o = System.Web.HttpContext.Current.Session["USER"];
??????????? if (o == null)
??????????????? return false;
??????????? else
??????????????? return true;
??????? }
??????? /// <summary>
??????? /// 登記User Session
??????? /// </summary>
??????? /// <param name="userinfo"></param>
??????? public static void CreateUserSession(UserSession userinfo)
??????? {
??????????? System.Web.HttpContext.Current.Session["USER"] = userinfo;
??????? }
??????? /// <summary>
??????? /// 獲取User Session
??????? /// </summary>
??????? /// <returns></returns>
??????? public static UserSession GetUserSession()
??????? {
??????????? object o = System.Web.HttpContext.Current.Session["USER"];
??????????? if (o == null) throw new ExceptionSession("讀取UserSession失敗。");
??????????? else return (o as UserSession);
??????? }
??????? /// <summary>
??????? /// 移除User Session
??????? /// </summary>
??????? public static void RemoveUserSession()
??????? {
??????????? object o = System.Web.HttpContext.Current.Session["USER"];
??????????? if (o != null) System.Web.HttpContext.Current.Session.Remove("User");
??????? }
??????? #endregion
??????? #region 模塊Session操作
??????? /// <summary>
??????? /// 登記Moudule Session
??????? /// </summary>
??????? /// <param name="lists"></param>
??????? public static void CreateModuleList(ArrayList lists)
??????? {
??????????? System.Web.HttpContext.Current.Session["MODULE_TAG"] = lists;
??????? }
??????? /// <summary>
??????? /// 讀取模塊權限
??????? /// </summary>
??????? /// <returns></returns>
??????? public static ArrayList GetModuleList()
??????? {
??????????? object o = System.Web.HttpContext.Current.Session["MODULE_TAG"];
??????????? if (o == null) throw new ExceptionSession("讀取權限失敗。");
??????????? else return (o as ArrayList);
??????? }
??????? /// <summary>
??????? /// 移除模塊權限
??????? /// </summary>
??????? public static void RemoveModuleList()
??????? {
??????????? object o = System.Web.HttpContext.Current.Session["MODULE_TAG"];
??????????? if (o != null)
??????????? {
??????????????? System.Web.HttpContext.Current.Session.Remove("MODULE_TAG");
??????????????? //在移除模塊權限時也清掉它的ID
??????????????? System.Web.HttpContext.Current.Session.Remove("MID");
??????????? }
??????? }
??????? #endregion
??????? #region 當前已登錄會員對當前模塊的權限集合
??????? /// <summary>
??????? /// 創建模塊權限列表
??????? /// </summary>
??????? /// <param name="lists"></param>
??????? public static void CreateAuthority(ArrayList lists)
??????? {
??????????? System.Web.HttpContext.Current.Session["Authority"] = lists;
??????? }
??????? /// <summary>
??????? /// 讀取模塊權限
??????? /// </summary>
??????? /// <returns></returns>
??????? public static ArrayList GetAuthority()
??????? {
??????????? object o = System.Web.HttpContext.Current.Session["Authority"];
??????????? if (o == null) throw new ExceptionSession("讀取權限失敗。");
??????????? else return (o as ArrayList);
??????? }
??????? /// <summary>
??????? /// 移除模塊權限
??????? /// </summary>
??????? public static void RemoveAuthority()
??????? {
??????????? object o = System.Web.HttpContext.Current.Session["Authority"];
??????????? if (o != null) System.Web.HttpContext.Current.Session.Remove("Authority");
??????? }
??????? #endregion
??? }
轉載于:https://www.cnblogs.com/xwnet/archive/2012/02/10/2345646.html
總結
以上是生活随笔為你收集整理的用于读、写、删除、比较Session中的用户信息的类库。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Net 4.0 Parallel 编程(
- 下一篇: Shader Compiler 界面进展