不知错在哪里,请大家指教!
Imports System.Web
Imports System.Web.HttpCookie
Imports System.Web.HttpCookieCollection
Imports System.Web.HttpRequest
'这是一个aspx的CodeBehind
Public Class WebForm1
Inherits System.Web.UI.Page
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Niname As HttpCookie
Dim Nipart As HttpCookie
Niname = Request.Cookies("aaa")
Nipart = Request.Cookies("bbb")
If Len(Trim(Request("filter_part"))) = 0 And Len(Trim(Request("name"))) = 0 Then
'下面以行错误!
If Len(Trim(Niname.Value)) > 0 And Len(Trim(Nipart.Value)) > 0 Then'错误行
retbool = "hello world"
End If
End If
End Sub
End Class
错误信息:
未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。
源错误:
行 33: Nipart = Request.Cookies("bbb")
行 34: If Len(Trim(Request("filter_part"))) = 0 And Len(Trim(Request("name"))) = 0 Then
行 35: If Len(Trim(Niname.Value)) > 0 And Len(Trim(Nipart.Value)) > 0 Then
行 36: retbool = "hello world"
行 37: End If
源文件: c:\inetpub\wwwroot\ncioa\login.aspx.vb 行: 35
堆栈跟踪:
[NullReferenceException: 未将对象引用设置到对象的实例。]
ncioa.WebForm1.retbool() in c:\inetpub\wwwroot\ncioa\login.aspx.vb:35
ncioa.WebForm1.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\ncioa\login.aspx.vb:25
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()