Click here to Skip to main content
15,913,854 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am implementing remember me checkbox for password i implemented like

C#
if (TextBox1.Text == "user" && TextBox2.Text == "user")
       {
           Response.Redirect("Default2.aspx");
       }
       if (CheckBox1.Checked)
       {
           HttpCookie cookie = new HttpCookie("username");
           cookie.Value = TextBox2.Text;
           cookie.Expires = DateTime.Now.AddHours(2);
           HttpContext.Current.Response.AppendCookie(cookie);
       }
       else
       {
           HttpContext.Current.Response.Cookies.Remove("username");
           Response.Cookies["username"].Expires = DateTime.Now;
       }

but not working can any body know please help me
Posted

this[^] blog might help you.
 
Share this answer
 
Why to re-inventing the wheel? You can achive this by using FormsAuthentication. ASP.NET provides this functionality out of the box....see the following link

http://msdn.microsoft.com/en-us/library/xdt4thhy.aspx[^]
 
Share this answer
 
You need to change your code.
Please use the following code.Hope it will work.If doesn't fulfill your requirement, please fell free to leave your comment.
try
       {
           if (!String.IsNullOrEmpty(TextBox1.Text) && !String.IsNullOrEmpty(TextBox2.Text))
           {
               if (CheckBox1.Checked)
               {
                   if (Request.Cookies["login"] != null)
                   {
                       HttpCookie getCookie = Request.Cookies.Get("login");
                       Response.Redirect("Default2.aspx?UserName : '" + getCookie.Values["UserName"].ToString() + "' & Password : '" + getCookie.Values["Password"].ToString() + "'");
                   }
                   else
                   {
                       HttpCookie cookie = new HttpCookie("login");
                       Response.Cookies.Add(cookie);
                       cookie.Values.Add("UserName", TextBox1.Text.ToString());
                       cookie.Values.Add("Password", TextBox2.Text.ToString());
                       cookie.Expires = DateTime.Now.AddHours(2);
                   }
               }
               else
               {
                   HttpContext.Current.Response.Cookies.Remove("login");
                   Response.Cookies["login"].Expires = DateTime.Now;
               }


           }
       }
       catch (Exception ex)
       {
           ex.ToString();
       }

If this would be really helpful to you then don't forgot to Vote and Make Answer as Accepted.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900