常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
行 16:     {
行 17: 
行 18:         if (Request.Cookies["name"].Value == "" || Request.Cookies["name"].Value == null)
行 19:         {
行 20:             Response.Redirect("default.aspx");
 
其中引起这现象不解啊+++++++++++++
我只要去除这个Cookies就正常!! Response.Cookies["SelectOrder"].Value = "";
与这有什么关系??????

解决方案 »

  1.   

    当然咯,你的Cookies["SelectOrder"]在未定义的时候,怎么能读取呢
    判断一下是否为null就行了,你即然定义了Cookies["SelectOrder"]就要不让他有空值的情况出现啊
      

  2.   

    赋值:Response.Cookies("name").Value = "xxx"  判断是不是空         
     Dim cookie As HttpCookie, read As String
    cookie = Request.Cookies("name")
    If Not cookie Is Nothing Then
       read = Request.Cookies("name").Value'有值再读
    End If
      

  3.   

    首先判断Request.Cookies["name"]是否为NULL.如果Request.Cookies["name"]是NULL的,那么自然就更不用去取Request.Cookies["name"].value了.因为在取Request.Cookies["name"]时就已经报NullReferenceException
    这个和Response.Cookies["SelectOrder"].Value = "";没有什么关系.也许是你业务逻辑的问题.
      

  4.   

    if (Request.Cookies["name"].Value == "" || Request.Cookies["name"].Value == null)
    ///////////
    先判断是否为null 然后再判断是否为""

    if (Request.Cookies["name"].Value == null || Request.Cookies["name"].Value == "")
      

  5.   

    .NET为了提高安全性 不允许使用为NLL的参数,变量的 你的Cookies肯定没赋值的 检查下代码 是逻辑错误 
    为NLL 和为空即""不是一回事啊 为""其实是有值的 只不过是空值罢了
      

  6.   

    我是想Cookies["SelectOrder"].Value !=null||Cookies["SelectOrder"].Value !=""就即行下面语句!为空就不执行了!!!从上面所说不能这样判断Cookies["SelectOrder"].Value !=null||Cookies["SelectOrder"].Value !=""???
    不会吧??
    嘿!笨脑,从上面也有了解,可以Response.Cookies["SelectOrder"].Value="InitData",只要不是InitData就即行!ASP.NET(VB.NET)我见有人这样判断
    If Not cookie Is Nothing Then
       read = Request.Cookies("name").Value'有值再读
    End If
    那么C#??
    Response.Cookies["SelectOrder"]==null???今天这样用过!不过后来不用Cookie了,但笨脑袋还是想了解更!!!
      

  7.   

    常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
    是不是先定义个 HttpCookie变量!
    HttpCookie  SelectOrder=new HttpCookie();
    SelectOrder=Request.Cookies["SelectOrder"];
    if(SelectOrder!=null)
    {
       我的操作;
    }
    这样是否可行????
      

  8.   

    楼上的同学正解
    要先判断是否为null
    /////错误的
    if(Request.Cookies["name"].Value == "" .......
    Cookies集合里面没有"name"这个元素,你拿没有的元素和一个字符串比较肯定是不对咯
    ////正确的
    if(Request.Cookies["name"]!=null ....