“/11”应用程序中的服务器错误。
--------------------------------------------------------------------------------未将对象引用设置到对象的实例。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
行 82:         int count = 0;
行 83:         string strUserName = " ";
行 84:         strUserName = Session["UserName"].ToString();
行 85:         string newcount = " ";
行 86:         SqlCommand comm = new SqlCommand();
 源文件: d:\lishisheng\11软件\LeftTree.aspx.cs    行: 84 堆栈跟踪: 
[NullReferenceException: 未将对象引用设置到对象的实例。]
   LeftTree.Page_Load(Object sender, EventArgs e) in d:\11\11软件\LeftTree.aspx.cs:84
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +47
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436 
--------------------------------------------------------------------------------
版本信息: Microsoft .NET Framework 版本:2.0.50727.1433; ASP.NET 版本:2.0.50727.1433 

解决方案 »

  1.   

    Session["UserName"]这个东西也许不存在的
    你应该判断一下
      

  2.   

    Session["UserName"].ToString(); 
    这个东西,你看看,是不是不存在.如果你单测这个东西,不是从过程上走的话,可能会取不到这个值的..
      

  3.   

    未将对象引用设置到对象的实例。这类的错误一般要从两点入手:一、找不对控件   二、对像为null时进行操作
      

  4.   

    你用VS调试下看下是不是Session["UserName"]为null 导致的了,我看九成是这个了
      

  5.   

    Session["UserName"]不存在。之前没有给其赋值
      

  6.   

    Session["UserName"]为null,不能tostring()
      

  7.   

    if(Session["UserName"] == null)
    {
      Response.Write("Session是空的,想把null值ToString()当然会异常了")
    }
      

  8.   


    if(Session["UserName"]!=null)
    strUserName = Session["UserName"].ToString(); 
      

  9.   

    请在83与84行之间插入判断
    if(Session["UserName"] != null) 
    {
    strUserName = Session["UserName"].ToString(); 
    string newcount = " "; 
    SqlCommand comm = new SqlCommand();
    .....
    }
      

  10.   

    Session["UserName"]不存在。之前没有给其赋值 如果直接取值就会错误