HttpCookie cookie = Request.Cookies[strKey];
if(null == cookie)
{
//cookie不存在
}

解决方案 »

  1.   

    Diadem(可乐可口)的方法没问题的,把strKey替换为你的Cookie变量名,出现“未将对象设置到对象实例”是因为该Cookie不存在你就对它进行操作了(比如获取值等),判断是否存在的方法就是楼上说的 if(null==cookie)。
      

  2.   

    try
    {
    HttpCookie cookie = Request.Cookies[strKey];
    if(null == cookie)
    {
    //cookie不存在
    }
    }
    catch
    {
    //cookie不存在}
      

  3.   

    HttpCookie cookie = new Request.Cookies(strKey);
    if(cookie == null)
    {
    //cookie不存在
    }
      

  4.   

    HttpCookie cookie = new Request.Cookies(strKey);
    这就实例 cookie 对象了
    如果没有其对象就 为null !
      

  5.   

    HttpCookie cookie = new Request.Cookies(strKey);
    if(cookie == null)
    {
    //cookie不存在
    }
      

  6.   

    http://www.cnblogs.com/aierong/archive/2004/07/14/23950.aspx
    http://www.cnblogs.com/aierong/archive/2004/07/14/24196.aspx
    注意:在获取Cookie的值之前,应该确保该 Cookie 确实存在。否则,您将得到一个异常
      

  7.   

    if(Request.Cookies["LoginName"]==null)
    {
        不存在
    }
    else
    {
        存在
    }
      

  8.   

    if(null==cookie) 这一招不错!
      

  9.   

    request.cookie["xxxx"] == null
      

  10.   

    null == cookie
    or
    cookie == null
    区别??