• 用户登录信息


    /// <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 "";
                }
            }

  • 相关阅读:
    css属性设置
    自由从摇篮开始 ——杨支柱
    提醒幸福
    随记
    那些回不去的年少时光(桐华)
    Javascript 与正则表达式
    XmlHttpRequest对象的获取及相关操作
    CSS的4种引入方式及优先级
    c#textBox控件限制只允许输入数字及小数点,是否为空
    c# 循环界面控件
  • 原文地址:https://www.cnblogs.com/di305449473/p/1193292.html
Copyright © 2020-2023  润新知