本文介绍了Cookie不适用于“记住我"复选框asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在实施记住我"复选框,以实现我实施的密码,例如
i am implementing remember me checkbox for password i implemented like
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
推荐答案
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();
}
如果这对您真的很有帮助,请不要忘记投票并接受答案.
这篇关于Cookie不适用于“记住我"复选框asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!