这是我在 Login.aspx 中的代码
protected void LoginButton_Click(object sender, EventArgs e)
{
HttpCookie loginCookie1 = new HttpCookie("loginCookie");
Response.Cookies["loginCookie1"].Value = LoginUser.UserName;
Response.Cookies.Add(loginCookie1);
}
这是在 shop.aspx
protected void btnAddCart_Click(object sender, EventArgs e)
{
HttpCookie myCookie = new HttpCookie(dvProduct.DataKey.Value.ToString());
myCookie["Category"] = dvProduct.DataKey["Category"].ToString();
myCookie["Product"] = dvProduct.DataKey["Product"].ToString();
myCookie["Quantity"] = txtQuantity.Text;
myCookie["Price"] = dvProduct.DataKey["Price"].ToString();
myCookie.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(myCookie);
Response.Redirect("ViewCart.aspx", true);
}
我想从 cookie 中读取用户名的值(在 login.aspx 中设置的值