• 记住登录用户,下次登录


    <td align="center" colspan="2">
                                        <input type="submit" id="btnLogin" value="登录" class="login-btn" /><input type="checkbox" name="checkMe" value="1"/>记住我<span id="errorMsg" style="font-size:14px;color:red"></span>
                                    </td>
    //记住我
                   if (!string.IsNullOrEmpty(Request["checkMe"]))
                   {
                       HttpCookie cookie1 = new HttpCookie("cp1", userInfo.UName);
                       HttpCookie cookie2 = new HttpCookie("cp2", Common.WebCommon.GetMd5String(Common.WebCommon.GetMd5String(userInfo.UPwd)));
                       cookie1.Expires = DateTime.Now.AddDays(3);
                       cookie2.Expires = DateTime.Now.AddDays(3);
                       Response.Cookies.Add(cookie1);
                       Response.Cookies.Add(cookie2);
                   }
    public ActionResult Index()
            {
                CheckCookieInfo();
                return View();
            }
    
    ----------------------------------------------------------
    
            #region 判断Cookie信息
              private void CheckCookieInfo()
              {
                  if (Request.Cookies["cp1"] != null && Request.Cookies["cp2"] != null)
                  {
                      string userName = Request.Cookies["cp1"].Value;
                      string userPwd = Request.Cookies["cp2"].Value;
                      //判断Cookie中存储的用户密码和用户名是否正确.
                     var userInfo=UserInfoService.LoadEntities(u=>u.UName==userName).FirstOrDefault();
                      
                     if (userInfo != null)
                     {
                         //注意:将用户的密码保存到数据库时一定要加密。
                         //由于数据库中存储的密码是明文,所以这里需要将数据库中存储的密码两次MD5运算以后在进行比较。
                         if (Common.WebCommon.GetMd5String(Common.WebCommon.GetMd5String(userInfo.UPwd)) == userPwd)
                         {
                             string sessionId = Guid.NewGuid().ToString();//作为Memcache的key
                             Common.MemcacheHelper.Set(sessionId, Common.SerializerHelper.SerializeToString(userInfo), DateTime.Now.AddMinutes(20));//使用Memcache代替Session解决数据在不同Web服务器之间共享的问题。
                             Response.Cookies["sessionId"].Value = sessionId;//将Memcache的key以cookie的形式返回到浏览器端的内存中,当用户再次请求其它的页面请求报文中会以Cookie将该值再次发送服务端。
                             Response.Redirect("/Home/Index");
                            
                         }
                     }
                     Response.Cookies["cp1"].Expires = DateTime.Now.AddDays(-1);
                     Response.Cookies["cp2"].Expires = DateTime.Now.AddDays(-1);
                  }
              }
    
            #endregion

     登录CONTROLLER不能集成BASECONTROLLER(任何用户都可访问)

  • 相关阅读:
    R学习之——R用于文本挖掘(tm包)
    【转】基于LDA的Topic Model变形
    Windows操作系统实习之读者写者问题
    应用《开场白》ios源码分享
    一个美式英语发音的app开源
    20款优秀的移动产品原型和线框图设计工具
    sqlite 数据库在ios中的使用
    28个UI免费漂亮的切换开关PSD下载
    ios应用程序生命周期
    Ludei HTML5平台将于今年夏季支持WebGL 3D技术
  • 原文地址:https://www.cnblogs.com/ecollab/p/6159135.html
Copyright © 2020-2023  润新知