记住我问题检查过的问题任何人都可以帮助我 [英] remember me problem checked problem can any one help me

查看:72
本文介绍了记住我问题检查过的问题任何人都可以帮助我的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,民谣

我有一个登录表单,如果我选中记住我"复选框,那么我想记住用户名和密码..

下面的代码是为了记住我..功能...它工作正常,但是只有一个问题...选中记住我"复选框后..如果我重新加载登录页面,选中的记住不保留"可以帮助我如何解决这个问题.....


谁能帮我...
我的代码就是这种方式...........请记住我...

下面的代码工作正常,只有问题检查了才记得还没有....

Hi folk''s

I have a login form in that if i check the remember me check-box,then i want to remember username and password ..

below code is for remember me.. functionality...it is working fine but only one problem ...After checking remember me check box.. if i reload login page the checked remember not remains can any one help me how can i resolve this problem.....


Can any one help me......
My code is in this way..........for remember me .....

Below code is working fine only problem is checked remember is not remains ....

protected void Page_Load(object sender, EventArgs e)
   {
       if (Page.IsPostBack)
       {
           if (chk_rem.Checked)
           {
               HttpCookie mycookie1 = new HttpCookie("mycookie1");
               //Response.Cookies.Remove("mycookie1");

               Response.Cookies.Add(mycookie1);

               mycookie1.Values.Add("Username", txt_username.Text);
               mycookie1.Values.Add("Password", txt_password.Text);
               DateTime dtex = DateTime.Now.AddDays(15);

               if (chk_rem.Checked == true)
               {
                   if (Request.Cookies["mycookie1"] != null)
                   {
                       HttpCookie getcookie1 = Request.Cookies.Get("mycookie1");
                       string un = getcookie1.Values["Username"].ToString();
                       string ps = getcookie1.Values["Password"].ToString();
                   }

               }

           }
           if (chk_rem.Checked == false)
           {
               Response.Cookies["mycookie1"].Expires = DateTime.Now.AddDays(-1);
           }
       }


       if (HttpContext.Current.Request.Cookies["mycookie1"] != null)
       {
           try
           {
               txt_username.Text = HttpContext.Current.Request.Cookies["mycookie1"]["Username"].ToString();
               string a = HttpContext.Current.Request.Cookies["mycookie1"]["Password"].ToString();
               txt_password.Attributes.Add("value", a);

               chk_rem.Checked = true;
           }
           catch { }
       }

   }


谢谢's& Regard's
mahesh.b.p.c


Thank''s&Regard''s
mahesh.b.p.c

推荐答案



您正在存储Cookie,以选中记住我"按钮.因此,您需要在第一个if条件之后添加一个条件.您可以检查Cookie是否存在,然后需要手动选中该复选框.您需要执行此操作,因为控件在下一次回发(刷新页面)后将永远不会保留其值.

即使存储了凭证,也无需显示该页面.只需重定向到用户的主屏幕即可.用户单击注销时,您可以删除Cookie,并且用户可以输入用户名&密码(这取决于您的要求).

Hi,

You are storing cookies for checked Remember me button. So you need to add one condition after first if condition. you can check if cookies exist then you need to manually check that checkbox. You need to do that because control never persist it''s value after next postback(refresh page).

And even if credential is stored then you do not need to display that page. just redirect to user''s home screen. At the time user click logout, you can remove cookies and user can enter username & password(this will depend upon your requirement).

if (Page.IsPostBack)
        {
            if (Response.Cookies["mycookie1"] != null)
            {
                chk_rem.Checked = true;
            }
            if (chk_rem.Checked)
            {
                HttpCookie mycookie1 = new HttpCookie("mycookie1");
                //Response.Cookies.Remove("mycookie1");
               
                Response.Cookies.Add(mycookie1);
               
                mycookie1.Values.Add("Username", txt_username.Text);
                mycookie1.Values.Add("Password", txt_password.Text);
                DateTime dtex = DateTime.Now.AddDays(15);
 
                if (chk_rem.Checked == true)
                {
                    if (Request.Cookies["mycookie1"] != null)
                    {
                        HttpCookie getcookie1 = Request.Cookies.Get("mycookie1");
                        txtUserName.Text = getcookie1.Values["Username"].ToString();
                        txtPassword.Password = getcookie1.Values["Password"].ToString();
                    }
 
                }
 
            }
            if (chk_rem.Checked == false)
            {
                Response.Cookies["mycookie1"].Expires = DateTime.Now.AddDays(-1);
            }
        }


希望你从上面的陈述中得到了主意,
谢谢
-Amit Gajjar


Hope you got the idea from above statement,
Thanks
-Amit Gajjar


这篇关于记住我问题检查过的问题任何人都可以帮助我的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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