首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

http get参数值的有关问题

2013-07-01 
http get参数值的问题string commentstring softnamecomment HttpUtility.UrlDecode(context.Request.

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

热点排行