0

我在 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(); 和解密字符串();是加密和解密密码的方法..

4

1 回答 1

0

您可以使用如下代码:

   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);
            }
       }

   }
于 2013-02-11T13:46:32.173 回答