/// <summary> /// 用户登录 /// </summary> /// <param name="username"></param> public int UserLogin(string username) { int result = 0; DataTable dt = userBll.SelectUserInfo(username); if (dt.Rows.Count > 0) { int uid = Convert.ToInt32(dt.Rows[0]["uid"].ToString()); string username1 = dt.Rows[0]["username"].ToString(); string loginIP = WebBasic.Text.Info.GetIP(); if (dt.Rows[0]["is_lock"].ToString() != "1")//账号被锁定 { //先退出登录 userMethod.UserAbandon(); //----将信息保存到Session---- Session["uid"] = dt.Rows[0]["uid"].ToString(); Session["username"] = dt.Rows[0]["username"].ToString(); Session["email"] = dt.Rows[0]["email"].ToString(); //----将信息保存到Cookie---- HttpCookie hc = new HttpCookie("UserInfo_up927"); hc.Values["uid"] = dt.Rows[0]["uid"].ToString(); hc.Values["username"] = HttpUtility.UrlEncode(dt.Rows[0]["username"].ToString()); hc.Values["pwd"] = Utils.Encrypt(dt.Rows[0]["pwd"].ToString()); //密码再次加密 hc.Values["email"] = dt.Rows[0]["email"].ToString(); hc.Values["usertype"] = dt.Rows[0]["usertype"].ToString();; //用户类别:1、普通用户 2、商家 hc.Expires = DateTime.Now.AddDays(3); //if (cookie_domain != "") //{ // hc.Domain = cookie_domain; //} //if (this.chk_long.Checked == true) //{ // hc.Expires = DateTime.Now.AddDays(7);//长期登录 //} Response.Cookies.Add(hc); result = 1;//登录成功 } else { result = 3;//该用户已被锁定 } } return(result); }