예제 #1
0
        protected void btn_Click(object sender, EventArgs e)
        {
            string name = txt.Text.Trim();
            string paw  = pwd.Text.Trim();

            try
            {
                SqlDataReader dr = BuyerService.Login(name, paw);
                if (dr.Read())
                {
                    Session["Buyers_name"] = txt.Text;
                    Session["Buyers_id"]   = dr["Buyers_id"].ToString();
                    Response.Redirect("index.aspx");
                }
                else
                {
                    //MessageBox.Show("用户名或者密码错误 ");
                    pwd.Text = "";
                    pwd.Focus();
                }
            }

            catch (Exception ex)
            {
                Response.Write("错误原因:" + ex);
            }
        }
        public IActionResult BuyerLogInForm([FromBody] EntryLogInBuyer logInBuyer)   //买家登录
        {
            var buyer = service.Login(logInBuyer.ID, logInBuyer.password);

            if (buyer != null)
            {
                //设置cookie
                HttpContext.Response.Cookies.Append("buyerNickName", buyer.Nickname, new CookieOptions {
                    Expires = DateTime.Now.AddSeconds(3600)
                });
                HttpContext.Response.Cookies.Append("buyerID", buyer.BuyerId, new CookieOptions {
                    Expires = DateTime.Now.AddSeconds(3600)
                });
                //HttpContext.Response.Cookies.Append("buyerURL", buyer.Nickname, new CookieOptions { Expires = DateTime.Now.AddSeconds(3600) });
                return(Redirect("/Home/Index"));
            }
            else
            {
                JsonData jsondata = new JsonData();
                jsondata["buyerNickName"] = "找不到名称";
                jsondata["buyerPassword"] = "******";
                return(Json(jsondata.ToJson()));
            }
        }