哈哈
没有先判断Session["branch"]是否为空

解决方案 »

  1.   

    Session["branch"] 在这之前 没有定义
      

  2.   

    这个太垃圾了,我还买了48元,就是那个ASP.NET+SQL Server
    作者是 吴晨 张亮 张静
      

  3.   

    加一个判断
    if( Session["branch"] != null )
    {
      

  4.   

    先判断Session["branch"]是否为空if(Session["branch"] ==null)
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 最新版本:20070212http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  5.   

    if(( Session["branch"] != null ) && (Session["branch"].ToString()=="0"|| Session["branch"].ToString()=="1"|| Session["branch"].ToString()=="3"))
      

  6.   

    “/clientserver”应用程序中的服务器错误。
    --------------------------------------------------------------------------------未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 28:  {
    行 29:  // 在此处放置用户代码以初始化页面
    行 30:  if(( Session["branch"] != null ) && (Session["branch"].ToString()=="0"|| Session["branch"].ToString()=="1"|| Session["branch"].ToString()=="3"))
    行 31:  {
    行 32: 
     源文件: c:\inetpub\wwwroot\clientserver\main\client.aspx.cs    行: 30 堆栈跟踪: 
    [NullReferenceException: 未将对象引用设置到对象的实例。]
       clientserver.main.client.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\clientserver\main\client.aspx.cs:30
       System.Web.UI.Control.OnLoad(EventArgs e) +67
       System.Web.UI.Control.LoadRecursive() +35
       System.Web.UI.Page.ProcessRequestMain() +731 
    --------------------------------------------------------------------------------
    版本信息: Microsoft .NET Framework 版本:1.1.4322.573; ASP.NET 版本:1.1.4322.573
      

  7.   

    加一个判断
    if( Session["branch"] != null )
      

  8.   

    if(( Session["branch"] != null ) && (Session["branch"].ToString()=="0"|| Session["branch"].ToString()=="1"|| Session["branch"].ToString()=="3"))
    写是不对的,。。即使为空的话还会去判断那个||的。
    应该在这条件前判断是否为空
      

  9.   

    出书的作者一般都没真正学过几年C#,出书经验又不高(因为学.net的肯定不是老饼),出书流程又不严谨~~`出错很正常~~~~
      

  10.   

    if(convert.tostring(Session["branch"])=="0 ................)
      

  11.   

    楼主改了以后的语句只是少了一个括号而已.......if(( Session["branch"] != null ) && [这里加(] ...........[)])
      

  12.   

    重新登录一下或者设置一个错误页退回登录页面就行了,原来代码不改都行......
    不过我很反感用Session存那么多东西....也不喜欢用Session验证方式....
      

  13.   

    LZ居然敢买清华大学出版社出版的书?LZ你的钱闲得蛋疼 #-_-
      

  14.   

    Session["branch"]空的对象是不能tostring的