程序在本地运行正常,上传到服务器上就不行了,取不到验证码的session值  已经用null 判断了 session没有值 
  错误提示   未将对象引用设置到对象的实例。 
  又加了一个静态变量存放验证码,本地运行也正常(能读取到验证码值),但是一上传到服务器就不行了
  错误提示 未将对象引用设置到对象的实例。
高手啊 这是怎么了? 我快崩溃了

解决方案 »

  1.   

    这是验证码生成页面部分代码
    public void Page_Load(object sender, System.EventArgs e) 

    if (!IsPostBack) 

    // 
    // TODO : initialize 
    // 
    this._random = new Random(); 
    this._code = GetRandomCode(); 
    // 
    // TODO : use Session["code"] save the VerifyCode 
    // 
    Session["code"] = this._code;
    Session["code1"] = this._code;
    useryzm.yzm = this._code; // 
    // TODO : output Image 
    // 
    this.SetPageNoCache(); 
    this.OnPaint(); 


    这是单击按钮 将验证码的值显示到按钮上
     protected void dl_Click(object sender, EventArgs e)
        {
            if (Session["code1"] != null)
            {
                dl.Text = "ss"+Session["code1"].ToString().Trim(); // tb_Verify_Code.Text.Trim()+ ",,," + 
            }
            else
            {
                dl.Text = useryzm.yzm.ToString() ;
            }
        }
     关键问题是 本地运行没事 到服务器上就不行了
      

  2.   

    断点调试   看session值 是否为null
      

  3.   

    感谢各位大侠  我的问题解决了 虽然不知道究竟怎么回事 但是经过我 做如下设置 它变好了 
      首先 在web.config 里添加 
       <system.web>
    <sessionState  mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20"/>
    </system.web>
     然后 在Window服务中将ASP.NET State Service 启动
     最后 谢谢大家  谢谢大家
      

  4.   

    ASP.NET State Service 
    可以看看  应该会解答你的疑问