今天写了一个购物车类,用Cookie实现,要在构造函数那实现判断浏览器是否支持Cookie。

public bool IsAcceptCookie;
public ShoppingCart()
{
System.Web.HttpContext.Current.Response.Cookies[
"TestCookie"].Value = "ok";
System.Web.HttpContext.Current.Response.Cookies[
"TestCookie"].Expires = DateTime.Now.AddMinutes(1);

if (System.Web.HttpContext.Current.Request.Cookies["TestCookie"] == null)
IsAcceptCookie
= false;
else
{
IsAcceptCookie
= true;
System.Web.HttpContext.Current.Response.Cookies[
"TestCookie"].Expires = DateTime.Now.AddDays(-1);
}

}

当然,开始是没有   System.Web.HttpContext.Current. 这一段的

结果就报了   响应在此上下文中不可用   的错误

结果自然是加上就好了

相关文章:

  • 2022-01-09
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
猜你喜欢
  • 2021-07-30
  • 2022-01-20
  • 2021-11-29
  • 2021-05-26
  • 2021-06-29
相关资源
相似解决方案