我想在点击“记住我”复选框时将登录名和密码存储在cookie中。我的login.cshtml
看起来像input type="text"
,id="loginName"
和input type="password" id = "password"
。我怎么能这样做?
答案 0 :(得分:1)
试试这个
// create a cookie
HttpCookie loginName = new HttpCookie("loginName", model.LoginName);
loginName.Expires = DateTime.Today.AddMonths(12);
Response.Cookies.Add(loginName);
HttpCookie password= new HttpCookie("password", model.Password);
password.Expires = DateTime.Today.AddMonths(12);
Response.Cookies.Add(password);