
Items | 301
HttpContext
Class
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Collections Reference
The Context object in ASP.NET supports one collection, Items, and an array
called AllErrors.
AllErrors
ExceptionArray = Context.AllErrors
Returns an array of Exception objects representing all accumulated errors that
occurred in the current request.
As in classic ASP, the Server.GetLastError method returns an ASPError object.
This mechanism is still available, though the returned value is now of type Excep-
tion rather than ASPError.
Parameters
None.
Example
The example checks to see if the AllErrors array contains any elements and if so,
displays them:
Sub Page_Load( )
Dim i as Integer
Dim e As New Exception("A generalized error.")
Context.AddError(e)
If Not Context.AllErrors Is Nothing Then
For i = 0 to Context.AllErrors.Length - 1
Message.Text = Message.Text & _
"Exception: " & _
Context.AllErrors(i).ToString( ) & "<br/>"
Next
Else
Message.Text = "No Errors to report."
End if
End Sub
Notes
Unlike classic ASP, arrays in ASP.NET are zero-based, so the first element in any
collection or array will be 0, not 1. Thus, in the example above, the array is
indexed from 0 to Length - 1, not from 1 to Length.
Items
Context.Items(Name as String) = Value
Value
= Context.Items(Index as Integer)
Value = Context.Items(Name as String)
The Items collection