• 尝试用户自动登录


    //尝试用户自动登录

    /// <summary>
            /// 尝试自动登录 或填充密码
            /// </summary>
            /// <param name="context"></param>
            /// <returns>自动登录后的状态:成功,填充密码,失败继续</returns>
            public static ConstStringHelper.AutoLoginResult TryAutoLoginOrMemoryPwd(HttpContext context,out string username,out string password)
            {
                username = ""; password = "";
                //尝试自动登录
                HttpCookie cookie_chkAutoLogin = context.Request.Cookies[ConstStringHelper.ADMINCOOKIE_CHKAUTOLOGIN];
                if (cookie_chkAutoLogin!=null && cookie_chkAutoLogin.Value=="true") 
                {
                    HttpCookie cookie_username = context.Request.Cookies[ConstStringHelper.ADMINCOOKIE_USERNAME];
                    HttpCookie cookie_password = context.Request.Cookies[ConstStringHelper.ADMINCOOKIE_PASSWORD];
                    if (cookie_username != null && cookie_password!=null)
                    {
                        if (CheckLoginStatus(context, cookie_username.Value, CommonHelper.DesDecode(cookie_password.Value)) == ConstStringHelper.LoginResult.OK)
                        {
                            return ConstStringHelper.AutoLoginResult.AutoLogin;
                        }
                    }
                }
                //尝试填充密码
                HttpCookie cookie_chkMemoryPwd = context.Request.Cookies[ConstStringHelper.ADMINCOOKIE_CHKMEMORYPWD];
                if (cookie_chkMemoryPwd != null && cookie_chkMemoryPwd.Value == "true")
                {
                    HttpCookie cookie_username = context.Request.Cookies[ConstStringHelper.ADMINCOOKIE_USERNAME];
                    HttpCookie cookie_password = context.Request.Cookies[ConstStringHelper.ADMINCOOKIE_PASSWORD];
                    if (cookie_username != null && cookie_password != null)
                    {
                        username = cookie_username.Value;
                        password = CommonHelper.DesDecode(cookie_password.Value);
                        return ConstStringHelper.AutoLoginResult.MemoryPwd;
                    }
                }
                return ConstStringHelper.AutoLoginResult.NO;
            }

    //存Cookie

    /// <summary>
            /// 把用户名和密码 存入cookie
            /// </summary>
            /// <param name="context"></param>
            /// <param name="username"></param>
            /// <param name="password"></param>
            public static void StoreCookie(HttpContext context, string chkMemoryPwd, string chkAutoLogin, string username, string password)
            {
                context.Response.SetCookie(new HttpCookie(ConstStringHelper.ADMINCOOKIE_CHKMEMORYPWD) { Value = chkMemoryPwd, Expires = DateTime.Now.AddDays(7) });
                context.Response.SetCookie(new HttpCookie(ConstStringHelper.ADMINCOOKIE_CHKAUTOLOGIN) { Value = chkAutoLogin, Expires = DateTime.Now.AddDays(7) });
                context.Response.SetCookie(new HttpCookie(ConstStringHelper.ADMINCOOKIE_USERNAME) { Value = username, Expires = DateTime.Now.AddDays(7) });
                context.Response.SetCookie(new HttpCookie(ConstStringHelper.ADMINCOOKIE_PASSWORD) { Value = CommonHelper.DesEncode(password), Expires = DateTime.Now.AddDays(7) });
            }

    //存Session

    /// <summary>
            /// 把用户id和用户名 存入session 
            /// </summary>
            /// <param name="context"></param>
            /// <param name="id"></param>
            /// <param name="username"></param>
            public static void StoreSession(HttpContext context,long id,string username)
            {
                context.Session[ConstStringHelper.ADMINSESSION_ID] = id;
                context.Session[ConstStringHelper.ADMINSESSION_USERNAME] = username;
            }
  • 相关阅读:
    经验大奉献。收集您的经验之你用什么方法提高.NET网站的性能!
    [书]:asp.net 2.0 高级编程(微软技术丛书)
    VS 2008 快捷键
    [书]:《Improving ASP.NET Performance》提高系统性能
    [书]:<<软件工程导论>> 听说很好,不知是真的否.
    [转] C#编码好习惯,献给所有热爱c#的同志
    [书]:UML和模式应用
    在后台代码里写 JS语句.
    查看和修改MTU值
    Lucene.NET搜索多个索引文件
  • 原文地址:https://www.cnblogs.com/adolphyang/p/4842010.html
Copyright © 2020-2023  润新知