使用了可能是null的变量,假如传递过来的参数是id你直接Response.Write(Request.Params["id"].ToString())就可能出现这个问题,应该
先if(Request.Params["id"] != null)判断下是否为null 再使用,看下你有没有可能为null的对象

解决方案 »

  1.   

    朋友们帮我看一下是不是这里有错!!!!我是一个菜鸟
    -----------------------------------------------------------------
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Web;
    using System.Web.SessionState;namespace anna 
    {
    /// <summary>
    /// Global 的摘要说明。
    /// </summary>
    public class Global : System.Web.HttpApplication
    {
    /// <summary>
    /// 必需的设计器变量。
    /// </summary>
    private System.ComponentModel.IContainer components = null; public Global()
    {
    InitializeComponent();
    }

    protected void Application_Start(Object sender, EventArgs e)
    {
    System.Data.SqlClient.SqlConnection sn=new System.Data.SqlClient.SqlConnection(Jet.ConStr);
    System.Data.SqlClient.SqlCommand sm=new System.Data.SqlClient.SqlCommand("select [desc] from an_about where name='power'",sn);
    sn.Open();
    Application["power"]=sm.ExecuteScalar();//anna权限大小
    sm.CommandText="select [value] from an_sys where name='clickcount'";//网站点击数
    Application["clickcount"]=sm.ExecuteScalar();
    sn.Close();
                Application["day"]=DateTime.Now.Day;
    }
     
    protected void Session_Start(Object sender, EventArgs e)
    {
    Session.Timeout=20;//设置会话超时时间
    Session["user"]=null;//用户名
    Session["id"]=null;//用户编号
    Session["gcount"]=0;//用户错误登陆次数
    Session["total"]=0;//定单总金额
    Session["temp"]="";//用于用户临时缓存
    //清除一天前的过期信息
    int day=(int)Application["day"];
    if (day!=DateTime.Now.Day)
    {
    Application.Lock();
    Application["day"]=DateTime.Now.Day;
    Application.UnLock();
    Jet.clear();
    }
    //插入用户IP
    System.Data.SqlClient.SqlConnection sn=new System.Data.SqlClient.SqlConnection(Jet.ConStr);
    System.Data.SqlClient.SqlCommand sm=new System.Data.SqlClient.SqlCommand("select count(*) from an_ip where ip='"+this.Request.UserHostAddress+"'",sn);
    sn.Open();
    if (((int)sm.ExecuteScalar())==0)
    {
    sm.CommandText="insert into an_ip (ip) values ('"+Request.UserHostAddress+"')";
    sm.ExecuteNonQuery();
    Application["clickcount"]=(int)Application["clickcount"]+1;//用户加加
    sm.CommandText="update an_sys set [value]="+Application["clickcount"].ToString()+" where name='clickcount'";
    sm.ExecuteNonQuery();
    }
    sn.Close();
    //______________________测试数据__________________________
    } protected void Application_BeginRequest(Object sender, EventArgs e)
    { } protected void Application_EndRequest(Object sender, EventArgs e)
    { } protected void Application_AuthenticateRequest(Object sender, EventArgs e)
    { } protected void Application_Error(Object sender, EventArgs e)
    { } protected void Session_End(Object sender, EventArgs e)
    { } protected void Application_End(Object sender, EventArgs e)
    { }

    #region Web 窗体设计器生成的代码
    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.components = new System.ComponentModel.Container();
    }
    #endregion
    }
    }