string comment;
string softname; comment = HttpUtility.UrlDecode(context.Request.QueryString["comment"].ToString());
softname = HttpUtility.UrlDecode(context.Request.QueryString["softname"].ToString());如果URL是http://192.168.0.241/comment.ashx?comment=XXX&softname=yyy 这样没问题
但是如果是http://192.168.0.241/comment.ashx?comment=XXX 程序就会报错难道querystring 在获取值之前非要判断一下是否存在吗 ?
为什么不是如果不存在就不赋值?
string softname; comment = HttpUtility.UrlDecode(context.Request.QueryString["comment"].ToString());
softname = HttpUtility.UrlDecode(context.Request.QueryString["softname"].ToString());如果URL是http://192.168.0.241/comment.ashx?comment=XXX&softname=yyy 这样没问题
但是如果是http://192.168.0.241/comment.ashx?comment=XXX 程序就会报错难道querystring 在获取值之前非要判断一下是否存在吗 ?
为什么不是如果不存在就不赋值?
{
//不为空
}
else
{
//为空!
}
//这样就不会报错了!
softname = HttpUtility.UrlDecode(context.Request.QueryString["softname"].ToString());=》comment = HttpUtility.UrlDecode(context.Request.QueryString["comment"]??"");
softname = HttpUtility.UrlDecode(context.Request.QueryString["softname"]??"");
这样就行了,谁让你没事就ToString()来着?没有就是null
建议学学java的方法 ,虽然不怎么好看Request.QueryString["comment"]+""