2013-02-11 41 views
0

我在asp.net和c#中工作。在我的应用程序中,我有登录页面,我记住了我的功能。我的代码在Firefox中运行良好,但不能在Chrome和IE中工作。请让我知道我错在哪里..记住我不工作铬和IE

CODE

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();是用于加密和解密密码的方法..

+0

你检查你的浏览器设置(Chrome和IE)。记住Cookie的选项可能被禁用。 – 2013-02-11 13:55:37

回答

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

    }