日期:2014-05-17  浏览次数:20529 次

http get参数值的问题
    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 在获取值之前非要判断一下是否存在吗 ?
为什么不是如果不存在就不赋值?

------解决方案--------------------
comment = HttpUtility.UrlDecode(context.Request.QueryString["comment"].ToString());
        softname = HttpUtility.UrlDecode(context.Request.QueryString["softname"].ToString());

=》

comment = HttpUtility.UrlDecode(context.Request.QueryString["comment"]??"");
        softname = HttpUtility.UrlDecode(context.Request.QueryString["softname"]??"");
------解决方案--------------------
HttpUtility.UrlDecode(context.Request.QueryString["comment"])
这样就行了,谁让你没事就ToString()来着?没有就是null