ashx出现错误,帮忙看下这段代码并发的时候有没有问题

[复制链接]
查看11 | 回复4 | 2021-1-27 07:20:45 | 显示全部楼层 |阅读模式
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
{
intnum=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(Exceptionex)
{
thrownewException(ex.Message);
//HttpContext.Current.Response.Write("{\"flag\":\"-1\",\"msg\":\"程序错误"+newException(ex.Message)+"\"}");
}

做的一个投票,大概一分钟内有100-200个请求
IIS事件监控这段代码报错自己测试并没有错误
Eventmessage:Anunhandledexceptionhasoccurred.
Exceptioninformation:
Exceptiontype:NullReferenceException
Exceptionmessage:Objectreferencenotsettoaninstanceofanobject.
atWAP.Global.Application_BeginRequest(Objectsender,EventArgse)
atSystem.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()

分 -->
回复

使用道具 举报

千问 | 2021-1-27 07:20:45 | 显示全部楼层
NullReferenceException
你这不是并发问题,而是某个对象为null,空指针异常。
回复

使用道具 举报

千问 | 2021-1-27 07:20:45 | 显示全部楼层
catch(Exceptionex)
{
thrownewException(ex.Message);
}
这种代码也太烂了吧?既然你要抛出这个异常,为什么只抛出ex.Message?为什么还要写try...catch?
取消try...catch,你从页面上的异常报错(在web.config中将用户定义异常处理属性配置为Off,然后看“黄页”信息)就能看到出错在哪一条语句了。
在开发调试环境,还是缺少测试用例,没有拿一些真实的测试数据来测试。说明你们开发缺质量,未测试的东西就直接上线。
回复

使用道具 举报

千问 | 2021-1-27 07:20:45 | 显示全部楼层
引用楼主liyunfei9558的回复:自己测试并没有错误
程序员说这种话我们其实都明白是什么意思。
这就是没有测试,只是用鼠标“点点点”几下而已。
回复

使用道具 举报

千问 | 2021-1-27 07:20:45 | 显示全部楼层
你自己将stack信息给封装掉了……
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行