如何在MVC 2.0中不使用记忆的情况下在登录页面中设置记住我 [英] How to set remember me in login page without using membeship in MVC 2.0

查看:76
本文介绍了如何在MVC 2.0中不使用记忆的情况下在登录页面中设置记住我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MVC 2.0.如果用户单击检查登录,我想设置一个烹饪方法来登录用户1年.我不希望用户对此进行任何身份验证.我的模型如下:

I am using MVC 2.0. I want to set a cooking to login the user for 1 year if user click on the check for login. I dont want user any authentication for this. my model is as follow :

 [Required(ErrorMessage = "Please Enter Email Address")]
        [DisplayName("User Name")]
        public string UserName { get; set; }

        [Required(ErrorMessage = "Please Enter Password")]
        [DataType(DataType.Password)]
        [DisplayName("Password")]
        public string Password { get; set; }

        [DisplayName("Remember Me")]
        public bool RememberMe { get; set; }

,并且在视图中,我正在使用HTML.CkeckboxFor.

and in the view i am using HTML.CkeckboxFor.

推荐答案

控制器的位置执行此操作:

Th the post of the controller do this :

if (model.RememberMe == true)
                    {

                        Response.Cookies["Login"]["UserName"] = model.UserName;
                        Response.Cookies["Login"]["Password"] = model.Password;
                        Response.Cookies["Login"].Expires = DateTime.Now.AddYears(1);
                    }

并在控制器中执行以下操作:

and in the get of controller do this :

HttpCookie cookie = Request.Cookies ["Login"];

HttpCookie cookie = Request.Cookies["Login"];

if (cookie != null)
            {
                model.UserName = cookie.Values[0];
                model.Password = cookie.Values[1];
}

这篇关于如何在MVC 2.0中不使用记忆的情况下在登录页面中设置记住我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆