zoukankan      html  css  js  c++  java
  • 用户登录信息

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

  • 相关阅读:
    css3 边框、背景、文本效果
    Java JDBC连接MYSQL数据库教程
    waf平台常用方法总结
    java比较两个日期大小
    js控制的弹出层
    js时间大小判断写法demo
    PL/SQL Developer技巧
    杀Oracle死锁进程方法
    查看oracle数据库的连接数以及用户
    Oracle分散问题记录
  • 原文地址:https://www.cnblogs.com/di305449473/p/1193292.html
Copyright © 2011-2022 走看看