首页 新闻 赞助 找找看

Request.QueryString iis 报错

0
悬赏园豆:15 [已关闭问题] 关闭于 2014-09-23 10:54

asp.net网页,服务端代码一加入以下代码。

string sno = Request.QueryString["sno"].ToString();

在本地运行正常。

发布iis7.0就报错,请大咖们赐教。。。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

wcsprogram的主页 wcsprogram | 初学一级 | 园豆:21
提问于:2014-09-23 10:48
< >
分享
所有回答(1)
0

string sno = Request.QueryString["sno"].ToString();

这句代码,当Request.QueryString["sno"]为null时,对空对象使用.ToString();

就会报错误: Object reference not set to an instance of an object

这是NET里面的经典错误了,都是使用对象属性或方法之前没有判断对象是否为空造成的。

爱编程的大叔 | 园豆:30839 (高人七级) | 2014-09-23 10:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册