Asp.Net Core MVC 记住密码

https://www.cnblogs.com/Hmd528/p/10695156.html

 

if (lm.RememberMe)
                    {
                        HttpCookie hc = new HttpCookie("UserInfo");
                        //在cookie对象中保存用户名和密码
                        hc["UserName"] = lm.UserName;
                        hc["UserPwd"] = lm.Password;
                        //设置过期时间
                        hc.Expires = DateTime.Now.AddDays(2);
                        //保存到客户端
                        Response.Cookies.Add(hc);
                    }
                    else
                    {

                        HttpCookie hc = new HttpCookie("UserInfo");
                        //判断hc是否空值
                        if (hc != null)
                        {
                            //设置过期时间
                            hc.Expires = DateTime.Now.AddDays(-1);
                            //保存到客户端
                            Response.Cookies.Add(hc);
                        }
                    }

posted @ 2021-04-20 13:33  LuoCore  阅读(487)  评论(0编辑  收藏  举报