一个系统登陆的时候出现这样的问题,但是并不是所有人都会出错未将对象引用设置到对象的实例。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪信息确定有关异常原因和发生位置的信息。  堆栈跟踪: 
[NullReferenceException: 未将对象引用设置到对象的实例。]
   rsgl.login.submit_Click(Object sender, EventArgs e) in D:\web\rsxt\login.aspx.cs:81
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain() +1277

解决方案 »

  1.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using rsgl.ywjk;
    using rsgl.jk;
    namespace rsgl
    {
    /// <summary>
    /// login 的摘要说明。
    /// </summary>
    public class login : System.Web.UI.Page
    {
    protected System.Web.UI.WebControls.TextBox username;
    protected System.Web.UI.WebControls.TextBox password;
    protected System.Web.UI.WebControls.Button submit;
    protected System.Web.UI.WebControls.TextBox imgcode;
    protected System.Web.UI.WebControls.Image Image1;
    protected System.Web.UI.WebControls.Label Label1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(!Page.IsPostBack)
    {
    this.Label1.Text="";
    }
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.submit.Click += new System.EventHandler(this.submit_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    #region  插入员工等录日志
    private void loginsert()
    {
    string xml="";

    string userip=Request.ServerVariables["REMOTE_ADDR"].ToString();

    rsgl.ywjk.Llog log=new Llog();
    Hashtable ht=new Hashtable();
    ht.Add("username",Session["username"].ToString());
            ht.Add("Ip",userip);
    ht.Add("drsj",System.DateTime.Now);
       log.logHashTable(ht,out xml);
    log.InsertLog(xml);
    }
    #endregion
    private void submit_Click(object sender, System.EventArgs e)
    {
    if(this.username.Text.Trim()=="" || this.password.Text.Trim()=="")
    {
    Response.Write("<script>alert('用户名和密码不能为空值!')</script>");
    }
    else
    {
    if(this.imgcode.Text.Trim().ToUpper()!=Session["checkcode"].ToString())  
    {  
    Response.Write("<script>alert('请确认您的验证码!')</script>");
    }
    else
    { rsgl.ywjk.check ic=new check();
    ic.Iusername=this.username.Text.ToString();
    ic.Ipassword=this.password.Text.ToString();
    System.Data.SqlClient.SqlDataReader dr=ic.ifadminexist();
    if(dr.HasRows)
    {
                       
    getadmin ga=new getadmin();
    ga=ic.getadmininfo(dr);
    Session["username"]=ga.username;
    Session["power"]=ga.power;
    Session["Cd"]=ga.Cd;
    Session["dqdm"]=ga.dqdm;
    loginsert();
    /*string js="<script>function close() { self.close(); }</script>"; if(!Page.IsClientScriptBlockRegistered("js"))
    {
    Page.RegisterClientScriptBlock("js",js);
    }*/
    // Response.Write("<script>window.opener='login.aspx';window.close();</script>");
    //Response.Redirect("main.aspx");
    Response.Write("<script langge=JavaScript>woiwo=window.open('main.aspx','woiwo','resizable=yes,scrollbars=no,toolbar=no,menubar=no,fullscreen=no');woiwo.moveTo(0,0); woiwo.resizeTo(screen.availWidth,screen.availHeight);woiwo.outerWidth=screen.availWidth;woiwo.outerHeight=screen.availHeight;window.opener='login.aspx';window.close();</script>");
    }
    else
    {
    this.Label1.Text="该用户不存在或密码错误!";
    this.Label1.Visible=true;
    }

    }
    }
    }
    }
    }
      

  2.   

    有个问题
    rsgl.login.submit_Click(Object sender, EventArgs e) in D:\web\rsxt\login.aspx.cs:81
    为什么会指向D:\web\rsxt\login.aspx.cs(这是我本地的)
    但是我访问的是服务器的为什么错误信息会指向我本地的