使用了可能是null的变量,假如传递过来的参数是id你直接Response.Write(Request.Params["id"].ToString())就可能出现这个问题,应该
先if(Request.Params["id"] != null)判断下是否为null 再使用,看下你有没有可能为null的对象
先if(Request.Params["id"] != null)判断下是否为null 再使用,看下你有没有可能为null的对象
解决方案 »
- onlineUsersHash.ContainsKey(Request.UserHostAddress)空指针异常
- 如何提取网页中Google Map的点
- 请问如何得到post 的URL
- 都进来看看这里有两个超级简单的问题
- 请大家指教一下,小妹非常感谢了!
- C#如何在Repeater取得CheckBox选中的某行某个值把值传给一个变量!
- 關於CrystalReport的一個小問題
- ASP.NET(C#)如何将SQL SERVER数据导出到EXCEL
- 彻底解决page_load问题,要专家做答!
- page语句中inheris
- 如何将客户端按钮的点击事件邦定到服务端按钮的点击事件上
- 改这个为网站收多少钱
-----------------------------------------------------------------
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
}
}