2013-02-11 58 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); 
      } 
     } 

    }