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

If MyCookies.Item("username").tostring() = "" Then 出错,该如何解决

2012-01-09 
If MyCookies.Item(username).tostring() Then出错代码如下:IfMyCookies.Item( username ).tostr

If MyCookies.Item("username").tostring() = "" Then 出错
代码如下:

If   MyCookies.Item( "username ").tostring()   =   " "   Then
                  T1.Visible   =true
                  T2.Visible   =false
Label1.Text   =   " "
else  
T1.Visible   =false
T2.Visible   =true
                  Label1.Text   =   MyCookies.Item( "truename ").ToString()
End   If
我在本机测试ok,能登陆和登出。
在别人的机器访问我的ip,第一行就抱错,错误信息如下:

异常详细信息:   System.NullReferenceException:   未设置对象变量或   With   块变量。
请帮忙分析下

[解决办法]
先判断MyCookies 是否为空
[解决办法]
不是判断为空 而是判断为null~~
If MyCookies.Item( "username ") = null Then
...
end if

[解决办法]
应该是ToString吧,大小写的问题啊
[解决办法]
If MyCookies.Item( "username ") <> Nothing
'do...

热点排行