用户登录信息

/// <summary>
        /// 用户是否登录
        /// </summary>
        public static bool UserIsLogin
        {
            get
            {
                if (HttpContext.Current.Session["B2CRegUserName"] == null)
                    return false;
                return true;
            }
        }

        /// <summary>
        /// 用户退出
        /// </summary>
        public static void LogonOut()
        {
            if (HttpContext.Current.Session["B2CRegUserName"] != null)
            {
                HttpContext.Current.Session["B2CRegUserName"] = null;
            }
            if (HttpContext.Current.Response.Cookies["B2CRegUserName"] != null)
            {
                HttpContext.Current.Response.Cookies["B2CRegUserName"].Value = "";
            }
            if (HttpContext.Current.Session["B2CUserType"] != null)
            {
                HttpContext.Current.Session["B2CUserType"] = null;
            }
        }

        /// <summary>
        /// 添加Session["B2CUserRegName"]
        /// </summary>
        /// <param name="username"></param>
        /// <param name="usertype"></param>
        public static void AddUserToSession(string username, string usertype)
        {
            if (false == UserIsLogin)
            {
                HttpContext.Current.Session["B2CRegUserName"] = username;
                HttpContext.Current.Session["B2CUserType"] = usertype;
            }
            else
            {
                if (!UserNameOfSession.Equals(username))
                {
                    HttpContext.Current.Response.Cookies["B2CRegUserName"].Value = username;
                    HttpContext.Current.Response.Cookies["B2CRegUserName"].Domain =
                        ConfigurationManager.AppSettings["B2CDomain"];
                    HttpContext.Current.Response.Cookies["B2CRegUserName"].Expires = DateTime.Now.AddDays(1);
                    HttpContext.Current.Session["B2CRegUserName"] = username;
                    HttpContext.Current.Session["B2CUserType"] = usertype;
                }
            }
        }

        /// <summary>
        /// 获取Session中的UserName值
        /// </summary>
        public static string UserNameOfSession
        {
            get
            {
                if (HttpContext.Current.Session["B2CRegUserName"] != null)
                    return HttpContext.Current.Session["B2CRegUserName"].ToString();
                return "";
            }
        }

        /// <summary>
        /// 获取Session中的UserType值
        /// </summary>
        public static string UserTypeOfSession
        {
            get
            {
                if (HttpContext.Current.Session["B2CUserType"] != null)
                    return HttpContext.Current.Session["B2CUserType"].ToString();
                return "";
            }
        }

转载于:https://www.cnblogs.com/di305449473/archive/2008/05/12/1193292.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值