ashx出现错误,帮忙看下这段代码并发的时候有没有问题
try
{
answer = int.Parse(context.Request.Params["answer"].ToString());
}
catch
{
answer = 0;
}
try
{
if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
{
ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else
{
ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
}
catch
{
ip = "";
}
try
{
int num = dal.VoteAdd(sid, qid, answer, ip);
if (num > 0)
{
HttpContext.Current.Response.Write("{\"flag\":\"1\",\"msg\":\"投票成功\"}");
}
else
{
HttpContext.Current.Response.Write("{\"flag\":\"0\",\"msg\":\"插入失败\"}");
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
//HttpContext.Current.Response.Write("{\"flag\":\"-1\",\"msg\":\"程序错误" + new Exception(ex.Message) + "\"}");
}
做的一个投票,大概一分钟内有100-200个请求
IIS事件监控 这段代码报错 自己测试并没有错误
Event message: An unhandled exception has occurred.
Exception information:
Exception type: NullReferenceException
Exception message: Object reference not set to an instance of an object.
at WAP.Global.Application_BeginRequest(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()