这是我从 XML 页面检索并通过将其存储在 cookie 中的页面,我想在另一个页面中检索它。
public partial class shopping : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
HttpCookie userCookie = new HttpCookie("user");
userCookie["quantity"] = TextBox1.Text;
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("shopping_cart.xml"));
XmlNode root = doc.DocumentElement;
if (RadioButton1.Checked)
{
string str1 = doc.GetElementsByTagName("cost").Item(0).InnerText;
userCookie["cost"] = str1;
//Label3.Text = str1;
Response.Redirect("total.aspx");
}
}
}
这是我试图检索它的其他页面(total.aspx.cs):
public partial class total : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
**Label2.Text = Request.Cookies["user"]["quantity"];**
}
}
我在粗体字的行上得到一个空引用。关于我该怎么做的任何建议?