[英]Remember me not working chrome and IE
我在asp.net和c#中工作。在我的應用程序中,我有一個記住我功能的登錄頁面。我的代碼在Firefox中工作良好,但在chrome和IE中不工作。請讓我知道我哪里出了錯。
代碼 :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.Cookies["Usermail"].Value != null && Request.Cookies["userpass"].Value != null)
{
txtemail.Text = Request.Cookies["Usermail"].Value;
txtpassword.Attributes["value"] = DecryptString(Request.Cookies["userpass"].Value);
}
}
}
protected void btnlogin_Click1(object sender, EventArgs e)
{
if (chkremember.Checked)
{
ck.Expires = tkt.Expiration;
Response.Cookies["userpass"].Value = EnryptString(txtpassword.Text);
Response.Cookies["Usermail"].Value = txtemail.Text;
Response.Cookies["Usermail"].Expires = DateTime.Now.AddDays(30);
Response.Cookies["userpass"].Expires = DateTime.Now.AddDays(30);
}
}
注意 :這里EnryptString(); 和DecryptString(); 是用於加密和解密密碼的方法。
您可以使用如下代碼:
if (!IsPostBack)
{
if (Request.Cookies["userinfo"] != null)
{
HttpCookie objCookie = Request.Cookies["userinfo"];
txtUserName.Text = objCookie.Values["username"];
txtPassword.Attributes.Add("value", objCookie.Values["password"]);
chkRemember.Checked = true;
}
}
protected void btnlogin_Click1(object sender, EventArgs e)
{
if (chkremember.Checked)
{
if (Request.Cookies["userinfo"] != null)
{
HttpCookie objCookie = Request.Cookies["userinfo"];
objCookie.Values.Remove("username");
objCookie.Values.Remove("password");
objCookie.Values["username"] = txtUserName.Text.Trim();
objCookie.Values["password"] = txtPassword.Text.Trim();
objCookie.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(objCookie);
}
else
{
HttpCookie objCookie = new HttpCookie("userinfo");
objCookie.Values["username"] = txtUserName.Text.Trim();
objCookie.Values["password"] = txtPassword.Text.Trim();
objCookie.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(objCookie);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.