本地测试是没有问题的,但是传到服务器上就提示出现这个错误,
将对象引用设置到对象的实例。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。  堆栈跟踪: 
[NullReferenceException: 未将对象引用设置到对象的实例。]
   beiertai.All_Send.Page_Load(Object sender, EventArgs e) in F:\工作资料\beiertai\beiertai\beiertai\All_Send.aspx.cs:25
   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
下面是代码:
23       protected void Page_Load(object sender, EventArgs e)
24        {
25            if (Session["User_id"].ToString() == "" || Session["User_id"].ToString() == null)
26            {
27                Response.Write("<script language='javascript'>window.alert('权限不足,请先登录后操作!');window.location.href='Login.aspx';</script>");
28            }
29
30            btnfind.Attributes.Add("onClick","return findcheck();");
31            if (!IsPostBack)
32            {
33                dgBind();
34            }
35            btnDelete.Attributes.Add("onClick", "return confirm('您真的要删除吗?');");
36
37        }

解决方案 »

  1.   

    应该是Session["User_id"].ToString() 出了问题,先判断是否NULL
      

  2.   

    Session["User_id"].ToString() == "" || Session["User_id"].ToString() == null
    交换一下或运算符左右两边的位置。
      

  3.   


    //改成这样
     if (Session["User_id"] == null && Session["User_id"].ToString() == "" ) 
                { 
                    Response.Write(" <script language='javascript'>window.alert('权限不足,请先登录后操作!');window.location.href='Login.aspx'; </script>"); 
                } 
      

  4.   

    string stru= Session["User_id"]==null?"":Session["User_id"].ToString();
    if (stru.length<=0) 
                { 
                    Response.Write(" <script language='javascript'>window.alert('权限不足,请先登录后操作!');window.location.href='Login.aspx'; </script>"); 
                } 
      

  5.   

    不行啊,换了也不行啊,我在本地测试的就没有问题,传到服务器上就出现错误了,   if (Session["User_id"].ToString() == "" || Session["User_id"].ToString() == null) 
    都是这一句有问题。
      

  6.   

    string stru= Session["User_id"]==null?"":Session["User_id"].ToString(); 
    if (stru.length <=0) 
                { 
                    Response.Write(" <script language='javascript'>window.alert('权限不足,请先登录后操作!');window.location.href='Login.aspx'; </script>"); 
                } 这样改过之后,直接提示上面的错误,原来是登陆后大约快2分钟的时候提示。。
      

  7.   


    string stru= Session["User_id"]==null?"":Session["User_id"].ToString();
    if (string.IsNullOrEmpty(stru))
    {
    Response.Write("  <script language='javascript'>window.alert('权限不足,请先登录后操作!');window.location.href='Login.aspx';  </script>");
    }
    如果这样都错,那就不是这个地方的问题了
      

  8.   

    确定web的用户权限了吗!特别是读写权限!