关闭浏览器清除Cookies
小弟现在在做一个购物车,用CookiesHttpCookie hc = null;
if (Request.Cookies["MyGouWuChe"] == null)
{
hc = new HttpCookie("MyGouWuChe");
}
else
{
hc = Request.Cookies["MyGouWuChe"];
}
if (Request.QueryString["ShopGoodsInfoCode"] != null && Request.QueryString["ShopGoodsName"] != null && Request.QueryString["BuyCount"] != null && Request.QueryString["Price"] != null)
{
if (hc.Values == null)
{
hc.Values.Add(Request.QueryString["ShopGoodsInfoCode"].ToString(), Request.QueryString["ShopGoodsInfoCode"].ToString() + "|" + Request.QueryString["ShopGoodsName"].ToString() + "|" + Request.QueryString["BuyCount"].ToString() + "|" + Request.QueryString["Price"].ToString());
hc.Expires = DateTime.Now.AddMinutes(30);//过期时间为30分钟
Response.Cookies.Add(hc);
}
else
{
hc.Values.Add(Request.QueryString["ShopGoodsInfoCode"].ToString(), Request.QueryString["ShopGoodsInfoCode"].ToString() + "|" + Request.QueryString["ShopGoodsName"].ToString() + "|" + Request.QueryString["BuyCount"].ToString() + "|" + Request.QueryString["Price"].ToString());
hc.Expires = DateTime.Now.AddMinutes(30);//过期时间为30分钟
Response.Cookies.Add(hc);
}
}
现在想关闭浏览器的时候把购物车里面的数据全部清除了
在Global.asax里面的
程序代码:
void Application_End(object sender, EventArgs e) { Response.Cookies.Clear(); // 在应用程序关闭时运行的代码 }这样写就可以了?