我编写的一个小论坛,使用cookies保存用户登录信息,可是却出现了问题,请热心人帮忙看看:
代码如下(Vb.net写的):
sub Page_Load(sender as object,e as eventargs)
dim userName
userName=Request.Cookies("userInfo").value
if userName="" then
userNameLabel.Text="客人,您还没有登录。请点击下面的登录按钮。"
loginOutButton.Text="请点击这里登录"
else
userNameLabel.Text=userName
end if
end sub编译错误信息如下:
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 9: sub Page_Load(sender as object,e as eventargs)
行 10: dim userName
行 11: userName=Request.Cookies("userInfo").value
行 12: if userName="" then
行 13: userNameLabel.Text="客人,您还没有登录。请点击下面的登录按钮。"
源文件: c:\inetpub\wwwroot\WebTest\community\communityIndex.aspx 行: 11
这是为什么啊?我曾经成功的执行过,不知现在怎么出现了问题?
代码如下(Vb.net写的):
sub Page_Load(sender as object,e as eventargs)
dim userName
userName=Request.Cookies("userInfo").value
if userName="" then
userNameLabel.Text="客人,您还没有登录。请点击下面的登录按钮。"
loginOutButton.Text="请点击这里登录"
else
userNameLabel.Text=userName
end if
end sub编译错误信息如下:
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 9: sub Page_Load(sender as object,e as eventargs)
行 10: dim userName
行 11: userName=Request.Cookies("userInfo").value
行 12: if userName="" then
行 13: userNameLabel.Text="客人,您还没有登录。请点击下面的登录按钮。"
源文件: c:\inetpub\wwwroot\WebTest\community\communityIndex.aspx 行: 11
这是为什么啊?我曾经成功的执行过,不知现在怎么出现了问题?
objCookie.Values.Add("UserName", Me.TextBox1.Text)
objCookie.Expires = DateTime.Now.AddDays(1) '过期期限设置为1天
Response.AppendCookie(objCookie)
if(Request.Cookies("userInfo") != null)
{
userName=Request.Cookies("userInfo").value ;
}
If Request.Cookies("userinfo") Is Nothing Then
userNameLabel.Text="客人,您还没有登录。请点击下面的登录按钮。"
loginOutButton.Text="请点击这里登录"
else
userNameLabel.Text=Request.Cookies("userinfo").Value
end if
end sub
谢谢,这里真是太好了,给分给分!