如何在mvc3中为登录名和密码创建cookie

时间:2013-09-03 05:21:51

标签: asp.net-mvc-3

我想在点击“记住我”复选框时将登录名和密码存储在cookie中。我的login.cshtml看起来像input type="text"id="loginName"input type="password" id = "password"。我怎么能这样做?

1 个答案:

答案 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);